【C++错误处理】no matching function for call to transform
2012-12-10 20:53
597 查看
作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
初学C++哈,不知道这个错误是不是很silly,高手轻拍。情况如下:
程序的意思很简单,去把Hello都转换为大写。
编译死活不通过:
后来查明原因如下——
我们先看看这个函数的定义:
template OutIter transform(InIter start, InIter end, OutIter result, Func unaryFunc)
它要求参数和返回值都要是char。Linux中将toupper实现为一个宏而不是函数:
/usr/lib/syslinux/com32/include/ctype.h:
/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
#define _toupper(__c) ((__c) & ~32)
#define _tolower(__c) ((__c) | 32)
__ctype_inline int toupper(int __c)
{
return islower(__c) ? _toupper(__c) : __c;
}
__ctype_inline int tolower(int __c)
{
return isupper(__c) ? _tolower(__c) : __c;
}
有三种解决方法:
1.因为在全局命名空间中有实现的函数(而不是宏),所以我们明确命名空间,这并不是总奏效,但是在我的g++环境中没有问题:
transform(str.begin(), str.end(), str.begin(), ::toupper);
2.自己写一个函数出来—wraper
inline char charToUpper(char c)
{
return std::toupper(c);
}
3.强制转化:将toupper转换为一个返回值为int,参数只有一个int的函数指针。
transform(str.begin(), str.end(), str.begin(), (int (*)(int))toupper);
作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
出处:http://www.cnblogs.com/gnuhpc/
初学C++哈,不知道这个错误是不是很silly,高手轻拍。情况如下:
#include #include #include using namespace std; int main (int argc, char * const argv[]){ string str = "Hello"; transform(str.begin(), str.end(), str.begin(), toupper); cout << str << endl; return 0; }
程序的意思很简单,去把Hello都转换为大写。
编译死活不通过:
$ g++ -g -Wall strToUpper.cpp -o strToUpper strToUpper.cpp: In function ‘int main(int, char* const*)’: strToUpper.cpp:9: error: no matching function for call to ‘transform(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, )’</CHAR*,></CHAR*,></CHAR*,>
后来查明原因如下——
我们先看看这个函数的定义:
template OutIter transform(InIter start, InIter end, OutIter result, Func unaryFunc)
它要求参数和返回值都要是char。Linux中将toupper实现为一个宏而不是函数:
/usr/lib/syslinux/com32/include/ctype.h:
/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
#define _toupper(__c) ((__c) & ~32)
#define _tolower(__c) ((__c) | 32)
__ctype_inline int toupper(int __c)
{
return islower(__c) ? _toupper(__c) : __c;
}
__ctype_inline int tolower(int __c)
{
return isupper(__c) ? _tolower(__c) : __c;
}
有三种解决方法:
1.因为在全局命名空间中有实现的函数(而不是宏),所以我们明确命名空间,这并不是总奏效,但是在我的g++环境中没有问题:
transform(str.begin(), str.end(), str.begin(), ::toupper);
2.自己写一个函数出来—wraper
inline char charToUpper(char c)
{
return std::toupper(c);
}
3.强制转化:将toupper转换为一个返回值为int,参数只有一个int的函数指针。
transform(str.begin(), str.end(), str.begin(), (int (*)(int))toupper);
作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
相关文章推荐
- 【C++错误处理】no matching function for call to transform
- C++ STL string 大小写转换时的 no matching function for call to ‘transform 错误
- C++ STL string 大小写转换时的 no matching function for call to ‘transform 错误
- C++中错误no matching function for call to transform
- C++常见错误之:no matching function for call to transform
- C++ o matching function for call to 'transform...错误
- C++ o matching function for call to 'transform...错误
- C++常见错误之:no matching function for call to transfor
- iOS linker错误之no matching function for call to ’recvfrom’
- no matching function for call to ‘transform
- G++编译错误 no matching function for call to '_tag_data_value::StringAddLen(std::string, int, int)
- [c++]no matching function for call to ‘sort(…)......
- no matching function for call to ‘transform
- no matching function for call to ‘transform
- Qt:no matching function for call to (类名)::connect()的错误原因总结
- no matching function for call to "namespace::class1::foo(class2&)"
- no matching function for call to 'strstr(stdstring&, const char [4])'
- 【求助】 no matching function for call to `strcpy(std::string&, char*&)'
- error: no matching function for call to 'std::exception:exception(const char[16])'
- error: no matching function for call to ‘boost::thread::thread(<unresolved overloaded function type>