Find the answer to your Linux question:
Results 1 to 2 of 2
This code compiles fine if I do not include iostream. Code: #include <cctype> #include <string> #include <algorithm> #include <iostream> int main &#40;&#41; &#123; std&#58;&#58;string test; std&#58;&#58;transform&#40;test.begin&#40;&#41;, test.end&#40;&#41;, test.begin&#40;&#41;, std&#58;&#58;tolower&#41;; return ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Nov 2004
    Location
    New York
    Posts
    150

    Template error with STL transform and cctype tolower functions


    This code compiles fine if I do not include iostream.

    Code:
    #include <cctype>
    #include <string>
    #include <algorithm>
    #include <iostream>
    
    int main &#40;&#41;
    &#123;
    	std&#58;&#58;string test;
    	std&#58;&#58;transform&#40;test.begin&#40;&#41;, test.end&#40;&#41;, test.begin&#40;&#41;, std&#58;&#58;tolower&#41;;
    	return 0;
    &#125;
    With it, I get
    Code:
    g++ test.cpp
    test.cpp&#58; In function ‘int main&#40;&#41;’&#58;
    test.cpp&#58;9&#58; error&#58; no matching function for call to ‘transform&#40;__gnu_cxx&#58;&#58;__normal_iterator<char*, std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> > >, __gnu_cxx&#58;&#58;__normal_iterator<char*, std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> > >, __gnu_cxx&#58;&#58;__normal_iterator<char*, std&#58;&#58;basic_string<char, std&#58;&#58;char_traits<char>, std&#58;&#58;allocator<char> > >, <unknown type>&#41;’
    I tried to look at the definition of tolower in the standard include header cctype, but all it did was undefine a C macro and add the C function to namespace std with a using declaration. The ctype.h file was almost incomprehensible to me, so if anyone has any ideas...

    Thanks.
    \"Nifty News Fifty: When news breaks, we give you the pieces.\" - Sluggy Freelance

  2. #2
    Linux Newbie
    Join Date
    Nov 2004
    Location
    New York
    Posts
    150
    I think I found the problem. The tolower function is declared inline in the system's standard include (/usr/include/c++/4.0.2/bits/localefwd.h), so passing a pointer to it to the transform function probably isn't a good idea. I guess this means I need to make a wrapper to use it.

    I wonder what the c++ standard has to say about pointers to standard functions - if it's valid for the implementation to make any of them inline, then none of them can ever safely be used as STL predicates.
    \"Nifty News Fifty: When news breaks, we give you the pieces.\" - Sluggy Freelance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •