Namespaces
Variants
Views
Actions

Talk:cpp/utility/functional/function

From cppreference.com

[edit] example code compilation problem

While the example code compiles fine using g++ (4.8.0) and clang++ (3.2) on my linux platform, it does not seem to compile using Visual Studio 2012, using either msvc++ or Intel C++ 13.1. The error I get can be found at the end of my post (sorry for the monster I pasted, but template errors often are just that). It seems to be an error related to the 'functional' header on windows.

 1>  main.cpp
 1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(516): error C2664: 'std::_Func_class<_Ret,_V0_t,_V1_t>::_Set' : cannot convert parameter 1 from '_Myimpl *' to 'std::_Func_base<_Rx,_V0_t,_V1_t> *'
 1>          with
 1>          [
 1>              _Ret=void,
 1>              _V0_t=const Foo &,
 1>              _V1_t=int
 1>          ]
 1>          and
 1>          [
 1>              _Rx=void,
 1>              _V0_t=const Foo &,
 1>              _V1_t=int
 1>          ]
 1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
 1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(516) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t,_V1_t>::_Do_alloc<_Myimpl,_Fret(__thiscall Foo::* const &)(int) const,_Alloc>(_Fty,_Alloc)' being compiled
 1>          with
 1>          [
 1>              _Ret=void,
 1>              _V0_t=const Foo &,
 1>              _V1_t=int,
 1>              _Fret=void,
 1>              _Alloc=std::allocator<std::_Func_class<void,const Foo &,int>>,
 1>              _Fty=void (__thiscall Foo::* const &)(int) const
 1>          ]
 1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(516) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t,_V1_t>::_Do_alloc<_Myimpl,_Fret(__thiscall Foo::* const &)(int) const,_Alloc>(_Fty,_Alloc)' being compiled
 1>          with
 1>          [
 1>              _Ret=void,
 1>              _V0_t=const Foo &,
 1>              _V1_t=int,
 1>              _Fret=void,
 1>              _Alloc=std::allocator<std::_Func_class<void,const Foo &,int>>,
 1>              _Fty=void (__thiscall Foo::* const &)(int) const
 1>          ]
 1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(516) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t,_V1_t>::_Reset_alloc<_Fret,Foo,int,std::allocator<_Ty>>(_Fret (__thiscall Foo::* const )(int) const,_Alloc)' being compiled
 1>          with
 1>          [
 1>              _Ret=void,
 1>              _V0_t=const Foo &,
 1>              _V1_t=int,
 1>              _Fret=void,
 1>              _Ty=std::_Func_class<void,const Foo &,int>,
 1>              _Alloc=std::allocator<std::_Func_class<void,const Foo &,int>>
 1>          ]
 1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(516) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t,_V1_t>::_Reset_alloc<_Fret,Foo,int,std::allocator<_Ty>>(_Fret (__thiscall Foo::* const )(int) const,_Alloc)' being compiled
 1>          with
 1>          [
 1>              _Ret=void,
 1>              _V0_t=const Foo &,
 1>              _V1_t=int,
 1>              _Fret=void,
 1>              _Ty=std::_Func_class<void,const Foo &,int>,
 1>              _Alloc=std::allocator<std::_Func_class<void,const Foo &,int>>
 1>          ]
 1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(675) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t,_V1_t>::_Reset<void,Foo,int>(_Fret (__thiscall Foo::* const )(int) const)' being compiled
 1>          with
 1>          [
 1>              _Ret=void,
 1>              _V0_t=const Foo &,
 1>              _V1_t=int,
 1>              _Fret=void
 1>          ]
 1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(675) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t,_V1_t>::_Reset<void,Foo,int>(_Fret (__thiscall Foo::* const )(int) const)' being compiled
 1>          with
 1>          [
 1>              _Ret=void,
 1>              _V0_t=const Foo &,
 1>              _V1_t=int,
 1>              _Fret=void
 1>          ]
 1>          c:\users\robbe\documents\projects\maxwell\src\scratch\main.cpp(30) : see reference to function template instantiation 'std::function<_Fty>::function<void(__thiscall Foo::* )(int) const>(_Fx &&)' being compiled
 1>          with
 1>          [
 1>              _Fty=void (const Foo &,int),
 1>              _Fx=void (__thiscall Foo::* )(int) const
 1>          ]
 1>          c:\users\robbe\documents\projects\maxwell\src\scratch\main.cpp(30) : see reference to function template instantiation 'std::function<_Fty>::function<void(__thiscall Foo::* )(int) const>(_Fx &&)' being compiled
 1>          with
 1>          [
 1>              _Fty=void (const Foo &,int),
 1>              _Fx=void (__thiscall Foo::* )(int) const
 1>          ]
 1>
 1>Build FAILED.
Documenting the bugs of individual compilers or libraries is generally beyond the scope of the wiki. Although major deficiencies sometimes appear in the "Notes" sections, it's hard to maintain such lists as compiler vendors keep releasing new versions. If you want to use equivalent functionality on a Windows platform, I recommend the boost.Function library]. --Cubbi 12:16, 7 April 2013 (PDT)
Thank you for the clarification. My intent was not to document platform deficiencies but to make sure the problem did not lie with the code.