Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7563 > unrolled thread
| Started by | eric <cneric12lin0@gmail.com> |
|---|---|
| First post | 2011-07-06 22:30 -0700 |
| Last post | 2011-07-06 23:26 -0700 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.c++
rtrimws: can't compile in g++ eric <cneric12lin0@gmail.com> - 2011-07-06 22:30 -0700
Re: rtrimws: can't compile in g++ Miles Bader <miles@gnu.org> - 2011-07-07 15:11 +0900
Re: rtrimws: can't compile in g++ eric <cneric12lin0@gmail.com> - 2011-07-06 23:26 -0700
| From | eric <cneric12lin0@gmail.com> |
|---|---|
| Date | 2011-07-06 22:30 -0700 |
| Subject | rtrimws: can't compile in g++ |
| Message-ID | <1495ae9f-43f4-47bc-967f-18a6bb54e7b4@t7g2000vbv.googlegroups.com> |
Dear advanced c++ programers: I copied and tested a piece simple Trimming string code from book c+ + cookbook in chapter4, section2 Example 4-4:Trim trailing whitespace. You can download and try it by yourself. ------------------------------------------------- http://examples.oreilly.com/9780596007614/ ------------------------------------------------------------------- in my g++ 4.5.2, compiler reponse -------------------- 4-4.cpp: In function ‘void rtrimws(std::string&)’: 4-4.cpp:21:21: error: too many arguments to function ‘void rtrimws(std::string&)’ 4-4.cpp:20:6: note: declared here ------------ according to the book, all book example code is compiled success in Visual C++ compiler so, please help Eric
[toc] | [next] | [standalone]
| From | Miles Bader <miles@gnu.org> |
|---|---|
| Date | 2011-07-07 15:11 +0900 |
| Message-ID | <buoipretybd.fsf@dhlpc061.dev.necel.com> |
| In reply to | #7563 |
eric <cneric12lin0@gmail.com> writes:
> --------------------
> 4-4.cpp: In function ‘void rtrimws(std::string&)’:
> 4-4.cpp:21:21: error: too many arguments to function ‘void
> rtrimws(std::string&)’
> 4-4.cpp:20:6: note: declared here
> ------------
The problem seems to be that there are multiple overloaded versions of
"isspace"[*], and the compiler doesn'tn know which one you want.
Changing the function that contains line 21 to the following seems to
make it work (though I dunno if it's the best solution):
// Overloads to make cleaner calling for client code
void rtrimws(string& s) {
rtrimws (s, static_cast<int(&)(int)> (isspace));
}
[I added the cast to "int(&)(int)" to force it to choose a particular
variant of isspace...]
[*] One is the usual "int isspace(int)", but there's _also_ this:
template<typename _CharT>
bool
isspace(_CharT, const locale&);
-Miles
--
Acquaintance, n. A person whom we know well enough to borrow from, but not
well enough to lend to.
[toc] | [prev] | [next] | [standalone]
| From | eric <cneric12lin0@gmail.com> |
|---|---|
| Date | 2011-07-06 23:26 -0700 |
| Message-ID | <71ee6cc2-9e43-4393-9f7d-669c07f66fb6@z12g2000yqj.googlegroups.com> |
| In reply to | #7564 |
On Jul 6, 11:11 pm, Miles Bader <mi...@gnu.org> wrote:
> eric <cneric12l...@gmail.com> writes:
> > --------------------
> > 4-4.cpp: In function ‘void rtrimws(std::string&)’:
> > 4-4.cpp:21:21: error: too many arguments to function ‘void
> > rtrimws(std::string&)’
> > 4-4.cpp:20:6: note: declared here
> > ------------
>
> The problem seems to be that there are multiple overloaded versions of
> "isspace"[*], and the compiler doesn'tn know which one you want.
>
> Changing the function that contains line 21 to the following seems to
> make it work (though I dunno if it's the best solution):
>
> // Overloads to make cleaner calling for client code
> void rtrimws(string& s) {
> rtrimws (s, static_cast<int(&)(int)> (isspace));
> }
>
> [I added the cast to "int(&)(int)" to force it to choose a particular
> variant of isspace...]
>
> [*] One is the usual "int isspace(int)", but there's _also_ this:
>
> template<typename _CharT>
> bool
> isspace(_CharT, const locale&);
>
> -Miles
>
> --
> Acquaintance, n. A person whom we know well enough to borrow from, but not
> well enough to lend to.
Thanks your suggestion, Eric
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web