我試圖編譯我在VS 2010中,編譯和GCC代碼工作,但我得到一個lambda表達式一個奇怪的錯誤:Lambda表達式,而不是與gcc
std::function<double (size_t level, size_t q)> doLevel = [&](size_t level, size_t q)
{ //line 52
double thisLevelP = density(q, data[level]);
if(level==T-1) return thisLevelP;
if(level==t-1) return thisLevelP*A(q,state)*doLevel(level+1,state);
double continuation = 0.0;
for(size_t i=0; i<Q; ++i)
{
continuation += A(q, i)*doLevel(level+1, i);
}
return thisLevelP*continuation;
};
的錯誤是:
Error 1 error C2086: 'size_t &_T' : redefinition c:\users\ga1009\documents\phd\cpp\pmi\cpp\test\baumiterationtest.cpp 52
Error 2 error C2661: '`anonymous-namespace'::`anonymous-namespace'::<lambda1>::<lambda1>' : no overloaded function takes 8 arguments c:\users\ga1009\documents\phd\cpp\pmi\cpp\test\baumiterationtest.cpp 52
出了什麼問題?
順便說一句,你有一些UB。在這種情況下,您需要明確指定lambda的返回類型。 – chris 2013-03-05 15:18:10
SSCCE如何? – 2013-03-05 15:19:13
哪條線是哪條線?表明這一點。我在發佈的代碼中沒有看到任何'size_t&_T'。 – Nawaz 2013-03-05 15:19:33