function with const parameters (MSVC 7.1)

Hello, I Tried to build a function Map. This is working for my. But if I change the function Parameter to const MSVC 7.1 failed to build. I am using boost 1.35 With gcc 4.3.1 i can compile it. Have some one a solution for me ? ##### source ##### #include <string> #include <map> #include <iostream> #include <boost/function.hpp> typedef boost::function<unsigned int (const bool)> measure_func; class X { public: X(void); unsigned int Exec(const std::string s,const bool b); protected: unsigned int f1(const bool b); unsigned int f2(const bool b); std::map<const std::string,measure_func> measure_map; }; X::X(void) { measure_map["1"]=std::bind1st(std::mem_fun(&X::f1), this); measure_map["2"]=std::bind1st(std::mem_fun(&X::f2), this); } unsigned int X::f1(bool b) { std::cout << "f1: " << b << std::endl; return 1; } unsigned int X::f2(bool b) { std::cout << "f2: " << b << std::endl; return 2; } unsigned int X::Exec(const std::string s,const bool b) { measure_func executer = measure_map[s]; if ( executer ) { return executer(b); } return 0; } // int main(int argc, char* argv[] ) // gcc main int _tmain(int argc, _TCHAR* argv[]) //VC main { X x; unsigned int n=x.Exec("1",true); std::cout << n << std::endl; return 0; } ####### MSVC 7.1 output ##### c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\functional(278) : error C2535: 'std::binder1st<_Fn2>::result_type std::binder1st<_Fn2>::operator ()(const std::binder1st<_Fn2>::argument_type &) const' : member function already defined or declared with [ _Fn2=std::mem_fun1_t<unsigned int,X,const bool> ] c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\functional(272) : see declaration of 'std::binder1st<_Fn2>::operator`()'' with [ _Fn2=std::mem_fun1_t<unsigned int,X,const bool> ] d:\Devel\test\Boost_test\Bind\Bind.cpp(29) : see reference to class template instantiation 'std::binder1st<_Fn2>' being compiled with [ _Fn2=std::mem_fun1_t<unsigned int,X,const bool> ] -- Bernd Martin Wollny TRIOPTICS GmbH - www.trioptics.com b.wollny@trioptics.com Hafenstrasse 39, 22880 Wedel/GERMANY Software Designer Geschäftsführer: Dipl.-Ing. Eugen Dumitrescu phone / fax: +49 (0)4103 18006-26 /-20 Amtsgericht Pinneberg HRB 3215

AMDG Bernd Martin Wollny wrote:
Hello,
I Tried to build a function Map. This is working for my. But if I change the function Parameter to const MSVC 7.1 failed to build. I am using boost 1.35 With gcc 4.3.1 i can compile it.
msvc 9.0 also compiles it.
Have some one a solution for me ?
##### source ##### #include <string> #include <map> #include <iostream> #include <boost/function.hpp>
typedef boost::function<unsigned int (const bool)> measure_func;
This is (or ought to be) exactly the same as typedef boost::function<unsigned int (bool)> measure_func;
class X { public: X(void); unsigned int Exec(const std::string s,const bool b);
Similarly, these const's have no effect. (Did you mean const std::string&) In Christ, Steven Watanabe

Steven Watanabe wrote:
AMDG
Bernd Martin Wollny wrote:
Hello,
I Tried to build a function Map. This is working for my. But if I change the function Parameter to const MSVC 7.1 failed to build. I am using boost 1.35 With gcc 4.3.1 i can compile it.
msvc 9.0 also compiles it.
Have some one a solution for me ?
##### source ##### #include <string> #include <map> #include <iostream> #include <boost/function.hpp>
typedef boost::function<unsigned int (const bool)> measure_func;
This is (or ought to be) exactly the same as
typedef boost::function<unsigned int (bool)> measure_func; With (bool) it's working ....
class X { public: X(void); unsigned int Exec(const std::string s,const bool b);
Similarly, these const's have no effect. (Did you mean const std::string&)
In Christ, Steven Watanabe
Hi Steven Watanabe, thanks for your replay, you are right: unsigned int Exec(const std::string s,const bool b); should be unsigned int Exec(const std::string &s,const bool b); this code is written in a very short time to illustrate my problem. So I think I have to wait until we change to MSVC 9.0 Have a nice weak Bernd -- Bernd Martin Wollny TRIOPTICS GmbH - www.trioptics.com bm.wollny@trioptics.com Hafenstrasse 39, 22880 Wedel/GERMANY
participants (2)
-
Bernd Martin Wollny
-
Steven Watanabe