boost:bind(&std:string:append, dst, src)(); 编译不过解决方法
boost::bind(&std::string::append, dst, src)(); 编译不过
两者有两个区别:
1. string是模版类
2. append有多个重载的函数 (经测试是这个原因)
要怎么解决这个问题呢?求解 (vs2010)
------解决思路----------------------
static_cast到你想要的类型:
------解决思路----------------------
用C++11的lambade,不要用boost::bind
#include <boost/bind.hpp>
#include <string>
struct test_t
{
int add(int x, int y)
{
return(x + y);
}
};
int main(int, char * [])
{
test_t test;
boost::bind(&test_t::add, test, 2, 3)(); // ok
std::string all;
std::string abc("abc");
boost::bind(&std::string::append, all, abc)(); // error
return(0);
}
两者有两个区别:
1. string是模版类
2. append有多个重载的函数 (经测试是这个原因)
要怎么解决这个问题呢?求解 (vs2010)
------解决思路----------------------
static_cast到你想要的类型:
static_cast<std::string& (std::string::*)(const std::string&)>(&std::string::append)
------解决思路----------------------
用C++11的lambade,不要用boost::bind