C++11 auto decltype 一个疑问
本帖最后由 sytpb 于 2016-06-06 16:01 编辑请教,代码如下
template<typename R>
auto GetFun2(int nType,R& r)->function<decltype(r)(string)>
{
if(nType == 1)
return [](string s){return stoi(s);};
}
void callGetFun2()
{
int r =100;
GetFun2(1,r);
}
callGetFun2()调用出错
ship.cpp:186:12: error: no viable conversion from '<lambda at ship.cpp:186:12>' to 'function<decltype(r) (string)>'
return [](string s){return stoi(s);}; decltype(r) 返回的类型为 int&
[](string s) {return stoi(s);}; 返回的类型为int 回复 2# panyi423
thanks 恍然大悟。
页:
[1]