g++ 没有匹配函数错误是指什么意思

downmooner 2012-01-05 08:31:26
strtxt.erase(
strtxt.begin(),
find_if(strtxt.begin(),strtxt.end(),not1(ptr_fun(isspace))));

报错对'ptr_fun(<unresolved overloaded function type>)'的调用没有匹配的函数.?
...全文
191 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
oxwuag 2012-01-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 mingliang1212 的回复:]

find_if(strtxt.begin(),strtxt.end(),not1(ptr_fun(isspace)));
应该不会有问题的...


提示什么错误 ?

find(strtxt.begin(),strtxt.end(),' ');//改成这样应该就没问题了
[/Quote]
isspace 效果不等同于' ',还有'\n''\t'等等,楼主疑问的是 为什么使用::isspace就可以了
oxwuag 2012-01-06
  • 打赏
  • 举报
回复
应该调用<cctype>里的isspace,而不是选择<locale>里的isspace函数模板

网上查了下,用到ptr_fun一般就会出这个问题,同时也找到了最佳解决办法

template < typename CharT >
class not_space
{
typedef std::ctype< CharT > char_type;
boost::shared_ptr< std::locale > the_loc_ptr;
char_type const * the_type_ptr;
public:
not_space ( std::locale const & r_loc = std::locale() )
: the_loc_ptr ( new std::locale ( r_loc ) )
, the_type_ptr ( &std::use_facet< char_type >( *the_loc_ptr ) )
{
}

bool operator() ( CharT chr )
{
return !( the_type_ptr->is(std::ctype_base::space,chr) );
}
};
//使用案例
strtxt.erase(
strtxt.begin(),
find_if( strtxt.begin(), strtxt.end(), not_space<char>() ) );


这样可以兼顾locale,也明确char类型而不是unsigned char,使用use_facet会提高性能(这个有待深入)
参照http://bytes.com/topic/c/answers/818665-ptr_fun-tolower-confusion
iamnobody 2012-01-05
  • 打赏
  • 举报
回复
find_if(strtxt.begin(),strtxt.end(),not1(ptr_fun(isspace)));
应该不会有问题的...


提示什么错误 ?

find(strtxt.begin(),strtxt.end(),' ');//改成这样应该就没问题了
downmooner 2012-01-05
  • 打赏
  • 举报
回复
::isspace

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧