首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于lambda表达式,该怎么解决

2013-02-02 
关于lambda表达式用vs2010写的#include vector#include string#include algorithmusing namespace s

关于lambda表达式
用vs2010写的


#include <vector>
#include <string>
#include <algorithm>

using namespace std;

class lambdatest
{
public:
int copy_();
private:
vector<string> temp2;
};
int lambdatest::copy_()
{
string _temp1[7]={"bgd_movie/bgd","bgd_zj/bgd","bgd_interact/bgd","toolbar/bgd","toolbar/bgd/Preferential","toolbar/bgd/Help","toolbar/bgd/Cooperation"};
vector<string> temp1(_temp1,_temp1+7);
//vector<string> temp2;
for_each(temp1.begin(),temp1.end(),[=,&(this->temp2)](string n)
{
temp2.push_back(n);
});
return 1;
}

int main()
{
lambdatest a;

return 1;
}



报错,
如果把[=,&(this->temp2)]改成[=,&temp2]报错:“lambdatest::temp2”: lambda 捕获变量必须来自封闭函数范围
[解决办法]
,&(this->temp2)都去掉

热点排行