func()
私は最近、このコードを呼び出すときにエラーメッセージを理解するのにかなりの時間を費やしました。
int main()
{
vector< vector<double> > v;
double sum = 0;
for_each( v.begin(), v.end(),
bind2nd( ptr_fun(func), &sum ) );
return 0;
}
そのように宣言されたときfunc()
、コードは正常にコンパイルされました:
void func( vector<double> v, double *sum )
{
}
この宣言を(効率のために)使用すると、コンパイラエラーが発生しました:
void func( const vector<double> &v, double *sum )
{
}
私が予想したエラーは、binder2ndのoperator()の定義のために、参照から参照へのエラーのようなものでした。
result_type operator()(const argument_type& _Left) const
代わりに、驚いたことに、Visual C ++(VS2012)コンパイラによって発生したエラーは次のとおりです。
エラーC2535:'void std :: binary2nd <_Fn2> :: operator()(const std :: vector <_Ty>&)const':メンバー関数はすでに定義または宣言されています
解読できません。
- どのメカニズム
operator()
ですでに定義されているか説明できますか?
私が得た完全なエラーは次のとおりです。
error C2535: 'void std::binder2nd<_Fn2>::operator ()(const std::vector<_Ty> &) const' : member function already defined or declared
with
[
_Fn2=std::pointer_to_binary_function<const std::vector<double> &,double *,void,void (__cdecl *)(const std::vector<double> &,double *)>,
_Ty=double
]
c:\vc\include\xfunctional(319) : see declaration of 'std::binder2nd<_Fn2>::operator ()'
with
[
_Fn2=std::pointer_to_binary_function<const std::vector<double> &,double *,void,void (__cdecl *)(const std::vector<double> &,double *)>
]
c:\consoleapplication1.cpp(31) : see reference to class template instantiation 'std::binder2nd<_Fn2>' being compiled
with
[
_Fn2=std::pointer_to_binary_function<const std::vector<double> &,double *,void,void (__cdecl *)(const std::vector<double> &,double *)>
]
Build FAILED.