[Bind] binding a functor simple example - compiler error
I'm having problems to compile a simple example and I don't Know what could it be the problem. my main.cpp code is the following: -- main.cpp ----------------------------------------------- #include <boost/bind.hpp> #include <iostream> int main() { struct F { int operator() (int a, int b) const { return a + b; } }; F f; std::cout << " f: " << boost::bind(f,1,2)() << std::endl; return 0; } ----------------------------------------------------------- I have the boost headers folder in the relative path "../../include" The command line i'm using to compile the file is @ g++ -I../../include -c main.cpp -o obj/Release/main.o but it returns the following error: no matching function for call to `bind(main()::F&, int, int)' I tried with 2 compilers but I get the same error from both: gcc versión 4.3.3 (Ubuntu 4.3.3-5ubuntu4) gcc version 3.4.5 (mingw-vista special r3) I'm using the Code::Blocks Editor and the MinGW compiler. Coud you help me to compile this simple example? Thanks a lot. \/iter :O)
Viter :O) wrote:
I'm having problems to compile a simple example and I don't Know what could it be the problem.
my main.cpp code is the following:
-- main.cpp ----------------------------------------------- #include <boost/bind.hpp> #include <iostream>
int main() { struct F { int operator() (int a, int b) const { return a + b; } }; F f;
std::cout << " f: " << boost::bind(f,1,2)() << std::endl;
return 0; } -----------------------------------------------------------
Please try moving F out of main, and say something about its result type, struct F { typedef int result_type; int operator() (int a, int b) const { return a + b; } }; int main() { F f; std::cout << " f: " << boost::bind(f,1,2)() << std::endl; return 0; } HtH, Rutger
participants (2)
-
Rutger ter Borg
-
Viter :O)