【发布时间】:2013-08-08 12:17:39
【问题描述】:
我正在尝试在 std::transform 中使用 boost::bind 连接两个字符串
假设我的类有两种方法来获取两个字符串(第一个和第二个),并且 conatiner 是字符串的向量,我试图做如下
struct Myclass
{
std::string getFirstString() {return string1}
std::string getSecondString() {return string2}
private:
std::string string1;
std::string string2;
}
Myclass myObj;
std::vector<string > newVec;
std::vector<myObj> oldVec;
std::transform (oldVec.begin(), oldVec.end(), std::back_inserter(newVec), boost::bind(&std::string::append,boost::bind(&getFirstString, _1),boost::bind(&getSecondString, _1 ) ) );
但是,我收到错误提示
error: cannot call member function 'virtual const getSecondString() ' without object
我在这里错过了什么?
【问题讨论】:
-
能否贴出oldVec、newVec、getSecondString、...的声明
-
还有
getFirstString。 -
你为什么不能在这里使用
for循环?
标签: c++ boost boost-bind