transform error in g++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jwwicks
    New Member
    • Oct 2007
    • 19

    transform error in g++

    Hello All,

    I'm getting an error in g++ when I try and compile a cpp file using transform...

    Here's the error...

    customer.cpp:42 9: error: no matching function for call to transform(__gnu _cxx::__normal_ iterator<char*, std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >, __gnu_cxx::__no rmal_iterator<c har*, std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >, __gnu_cxx::__no rmal_iterator<c har*, std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >, <unresolved overloaded function type>)

    The code in question is the following. #include <algorithm> is present and the code compiles no problem under Visual Studio. I know strictly speaking strings aren't containers but shouldn't this work or do you have to do something different for g++. Did MS include an overload that isn't in g++ ??

    Code:
    void gen_id( customer& c )
    {
    	string temp;
    	
    	temp = c.last_name;
    	temp += c.first_name.at(0);
    	transform( temp.begin(), temp.end(), temp.begin(), toupper);
    
    	temp += c.date->get( YEAR );
    	c.account = temp;
    }
    Here's a comment on the problem though I can't get to the FAQ mentioned...

    g++ Thread on bug
    John
    Last edited by jwwicks; Oct 6 '07, 09:57 PM. Reason: Add link to g++ comment
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Originally posted by jwwicks
    transform( temp.begin(), temp.end(), temp.begin(), toupper);
    This code should work OK.

    transform has two overloads. In one the 4th argument is a unary function and in the 2nd it is a binary function.

    toupper takes an int argument and returns an int. That quakifies uit as a unary function. Each character of the string will be passed to toupper by transform.

    It does concern me that your error message contains __normal_iterat or, which is not a standard STL iterator type.

    transform expects a string::iterato r, which is a normal forward iterator.

    I assume you are using the -pedantic switch with g++ to disable non-standard extensions, though I can't see what difference that would make here.

    Comment

    • jwwicks
      New Member
      • Oct 2007
      • 19

      #3
      Originally posted by weaknessforcats
      This code should work OK.

      I assume you are using the -pedantic switch with g++ to disable non-standard extensions, though I can't see what difference that would make here.
      I'll try the -pedantic switch to see if it helps...

      P.S.
      Tested with the -pedantic switch and no difference in errors...
      g++ (GCC) 4.1.0 20060304 (Red Hat 4.1.0-3)

      Thanks,
      John
      Last edited by jwwicks; Oct 8 '07, 08:53 PM. Reason: After testing the same bug occurs

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Then I havwe no idea. Your tranforms compiles OK using Visual Studio.NET 2005.

        Comment

        Working...