[Function] "constness" lost on Function Signature

main.cpp 1>..\main.cpp(22) : error C2679: '=' binaire : aucun opérateur trouvé qui accepte un opérande de partie droite de type 'bool (__cdecl *)(const int,float,float)' (ou il n'existe pas de conversion acceptable) 1> C:\Documents and Settings\dfc\Bureau\boost_1_44\boost/function/function_template.hpp(1103):
Hi, I am using boost::function and have some issues on using it with visual studio 2005. If I declare a boost::function with some "const" argument this "constness" seems to be lost on boost function siganture. Then, future assigment to this function whith correct "const" argument lead to wrong matching. See code snipset below. This work fine under gcc 4.4 and visual 2010. ---------------------------------------------------------------------------------- #include <iostream> #include <vector> #include <boost/function.hpp> using namespace std; using namespace boost; class container_test { public: typedef boost::function<bool(const int,float,float)> FunctionType; bool static defaultFunctor(const int, float, float) { return true; } //void apply_functor( const FunctionType IsInside = defaultFunctor){} }; int main() { container_test my_container; container_test::FunctionType my_f; my_f = container_test::defaultFunctor; //my_container.apply_functor(); return 0; } ---------------------------------------------------------------------------------- error send by visual 2005 compiler with "const". If change "const int" to "int" it works. ( sorry for the "french") ---------------------------------------------------------------------------------- peut être 'boost::function<Signature> &boost::function<Signature>::operator =<bool(__cdecl *)(int,float,float)>(Functor)' 1> with 1> [ 1> Signature=bool (int,float,float), 1> Functor=bool (__cdecl *)(int,float,float) 1> ] 1> C:\Documents and Settings\dfc\Bureau\boost_1_44\boost/function/function_template.hpp(1088): ou 'boost::function<Signature> &boost::function<Signature>::operator =(const boost::function<Signature> &)' 1> with 1> [ 1> Signature=bool (int,float,float) 1> ] 1> C:\Documents and Settings\dfc\Bureau\boost_1_44\boost/function/function_template.hpp(1110): ou 'boost::function<Signature> &boost::function<Signature>::operator =(boost::function<Signature>::clear_type *)' 1> with 1> [ 1> Signature=bool (int,float,float) 1> ] 1> C:\Documents and Settings\dfc\Bureau\boost_1_44\boost/function/function_template.hpp(1117): ou 'boost::function<Signature> &boost::function<Signature>::operator =(const boost::function3<R,T0,T1,T2> &)' 1> with 1> [ 1> Signature=bool (int,float,float), 1> R=bool, 1> T0=int, 1> T1=float, 1> T2=float 1> ] 1> lors de la tentative de mise en correspondance de la liste des arguments '(container_test::FunctionType, bool (__cdecl *)(const int,float,float))' ---------------------------------------------------------------------------------- Nicolas David

AMDG On 2/4/2011 1:53 AM, nicolas david wrote:
I am using boost::function and have some issues on using it with visual studio 2005. If I declare a boost::function with some "const" argument this "constness" seems to be lost on boost function siganture. Then, future assigment to this function whith correct "const" argument lead to wrong matching. See code snipset below. This work fine under gcc 4.4 and visual 2010.
---------------------------------------------------------------------------------- <snip> class container_test { public: typedef boost::function<bool(const int,float,float)> FunctionType; bool static defaultFunctor(const int, float, float) { return true; } //void apply_functor( const FunctionType IsInside = defaultFunctor){} }; <snip> ----------------------------------------------------------------------------------
error send by visual 2005 compiler with "const". If change "const int" to "int" it works. ( sorry for the "french")
This is a compiler bug. Whether the argument is declared const shouldn't affect anything outside of the function body. bool static defaultFunctor(const int, float, float); is exactly equivalent to bool static defaultFunctor(int, float, float); In Christ, Steven Watanabe

This is a compiler bug.
OK, thank you for the information
bool static defaultFunctor(const int, float, float);
is exactly equivalent to
bool static defaultFunctor(int, float, float);
You're right. I shoul'd better try with some "pass by const reference" and use struct or class on my example and not int/float Nicolas David
participants (2)
-
nicolas david
-
Steven Watanabe