我怎樣才能得到這個編譯?錯誤是當我開始使用boost :: ref()。我認爲boost :: ref用於傳遞對C++算法類的引用?正確使用Boost :: ref ..?
list<Object> lst;
lst.push_back(Object(1,2.0f));
lst.push_back(Object(3,4.3f));
struct between_1_and_10
{
int d;
void operator() (Object& value)
{
value.a += 5; value.b -= 3.3f;
cout << d << endl;
d += value.a;
}
};
between_1_and_10 val;
val.d = 4;
for_each(lst.begin(), lst.end(), boost::ref(val)); // Problem is here
printf("rg");
編輯這裏的編譯器錯誤的人建議:
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\algorithm(29) : error C2064: term does not evaluate to a function taking 1 arguments
1> c:\users\swangrun\desktop\minescout work\feat-000-gettargetimages\minescouttest\maintest.cpp(102) : see reference to function template instantiation '_Fn1 std::for_each<std::list<_Ty>::_Iterator<_Secure_validation>,boost::reference_wrapper<T>>(_InIt,_InIt,_Fn1)' being compiled
1> with
1> [
1> _Fn1=boost::reference_wrapper<main::between_1_and_10>,
1> _Ty=Object,
1> _Secure_validation=true,
1> T=main::between_1_and_10,
1> _InIt=std::list<Object>::_Iterator<true>
1> ]
好的。它應該在for_each()行上。但問題是什麼。您必須向我們提供錯誤或足夠的代碼,以便我們重現錯誤。 – 2009-07-08 01:43:45
問題是它不能編譯。我已經接受了答案,謝謝你的參與! – sivabudh 2009-07-08 01:50:38