bind is not a member of std - c++

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.

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.

You need to include the header functional. It is available in C++11. If you are still having problems, then your compiler may not support C++11 yet. Try upgrading.

You can also use boost::bind:
#include <boost/bind.hpp>

Related

Error "is_enum not declared in this scope" when trying to compile my wxWidgets program

The G++ compiler shows the following errors when I try to compile:
C:\wx\include\wx\strvararg.h|350|error: 'is_enum' in namespace 'std' does not name a template type|
C:\wx\include\wx\strvararg.h|354|error: 'is_enum' was not declared in this scope|
C:\wx\include\wx\strvararg.h|354|error: template argument 1 is invalid|
I am using Code::Blocks for this, with a non-monolithic DLL build of wxWidgets.
Thanks for any help!
As Brian already indicated, you should enable C++11. There are two ways of doing this as you can see What are the differences between -std=c++11 and -std=gnu++11?.
As I remember, when compiling the whole wxWidgets library, I used -std=gnu++11 and had no problems.
Just to add to macroland comment:
You should consider upgrading to gcc version 5.2+. This version(s) does have a full set of c++11 features, whereas previous versions have them partially.

No way to compile smart pointer with mingw-w64

I am using lasted mingw w64 compiler (from April 2014, with g++ 4.9.0), and I am unable to compile smart pointers (including <memory> header ), either with -std=c++0x or gnu0x. I get always same error:
error: 'shared_ptr' in namespace 'std' does not name a template type
I was told that lastest gcc was able to compile that. But this don't seem to be my case. I am missing anything?
Remove the -ansi compiler flag. For C++, it is equivalent to -std=c++98.
It comes after -std=c++11 and is overriding it. std::shared_ptr did not exist in C++98

string pop_back function error

I am having a problem with modifying a string. I appreciate your assistance; thank you!
struct Drawings::menues
{
std::vector<std::string> variable;
} Menue[numMenues];
Menue[1].variable.at(0).pop_back();
the above code gives me the following error
error: 'class std::basic_string<char>' has no member named 'pop_back'|
I am using codeblocks 12.11 and am using the gnu gcc compiler and the C++11 flag under compiler settings fixed my problem.
thank you all!
pop_back was introduced in C++11. Make sure your compiler supports it and compile with -std=c++11 (or -std=c++0x only if -std=c++11 is not supported on your version of the compiler).

array not a member of namespace::std

I am using g++ version 4.5.2 .
Although I have include array header file
#include <array> it does not complain about the existence of the header file.
But when I do std::array<char , 16>,
the exception is thrown when I try to compile with g++
"array not a member of namespace std"
I searched on the net and saw a suggestion somewhere to use std::tr1::array<>,
but that did not help either ?
Does someone know what the problem is ?
You need to compile with GCC 4.6 and later to have C++11 features and you need to set the right flag to -std=C++0x or in GCC 4.7 -std=C++11

C++ linux : error: ‘move’ is not a member of ‘std’ how to get around it?

So on my VS2010 I can compile code like :
boost::shared_ptr<boost::thread> internal_thread;
boost::packaged_task<void> internal_task_w(boost::bind(&thread_pool::internal_run, this, internal_thread));
internal_thread = boost::shared_ptr<boost::thread>( new boost::thread(std::move(internal_task_w)));
first 2 lines are ok with boost 1.47.0 and linux... but on std::move it gives error: ‘move’ is not a member of ‘std’. On VS2010 it does not require any special header. So I wonder which header it requires on linux and is it in its STD anyway? If not how to get around it with boost or something?
To get g++ into C++11 (or C++0x) mode, you have to add the command-line parameter -std=c++0x on versions <= 4.6, nowadays you can also use -std=c++11.
You are using the most recent Visual Studio, but not the most recent GCC. The std::move capability is available in the most recent GCC. It is a new feature of C++11.
You can't use std::move because your compiler does not support c++11.