I am using netbeans 7.2.1 with minwg compiler. I am getting the following error messages when trying to build the application:
error: 'function' in namespace 'std' does not name a type
error: 'bind' is not a member of 'std'
although I included functional.h in the begining of the file, and I am using 'function' and 'bind' in the form of: std::function and std::bind
Where is the problem? Is it in the compiler or there is something missing? I remember that I compiled and ran the same application successfully on visual studio 2010.
std::bind is a Standard Function Objects that acts as a Functional Adaptor i.e. it takes a function as input and returns a new function Object as an output with with one or more of the arguments of passed function bound or rearranged.
Bind function with the help of placeholders helps to manipulate the position and number of values to be used by the function and modifies the function according to the desired output. What are placeholders? Placeholders are namespaces that direct the position of a value in a function.
Internally, std::bind() detects that a pointer to a member function is passed and most likely turns it into a callable objects, e.g., by use std::mem_fn() with its first argument.
std::bind return type The return type of std::bind holds a member object of type std::decay<F>::type constructed from std::forward<F>(f), and one object per each of args... , of type std::decay<Arg_i>::type, similarly constructed from std::forward<Arg_i>(arg_i).
It is not functional.h
, it is just functional
.
#include <functional> //without .h
Note that std::function
and std::bind
come with C++11 only. So you might have to upgrade your compiler in case you have not done yet.
Also, compile your code with -std=c++11
option:
$ g++ -std=c++11 file.cpp
That should work if you've upgraded your compiler. If your compiler is a bit old, you can also try -std=c++0x
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With