简体   繁体   English

bind不是std的成员

[英]bind is not a member of std

I am using netbeans 7.2.1 with minwg compiler. 我使用netbeans 7.2.1与minwg编译器。 I am getting the following error messages when trying to build the application: 我在尝试构建应用程序时收到以下错误消息:

error: 'function' in namespace 'std' does not name a type 错误:命名空间'std'中的'function'没有命名类型

error: 'bind' is not a member of 'std' 错误:'bind'不是'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 虽然我在文件的开头包含了functional.h,我使用'function'和'bind'的形式:std :: function和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. 我记得我在visual studio 2010上成功编译并运行了相同的应用程序。

It is not functional.h , it is just functional . 它不是functional.h ,它只是functional

#include <functional> //without .h

Note that std::function and std::bind come with C++11 only. 请注意, std::functionstd::bind仅与C ++ 11一起提供。 So you might have to upgrade your compiler in case you have not done yet. 所以你可能必须升级你的编译器,以防你还没有完成。

Also, compile your code with -std=c++11 option: 另外,使用-std=c++11选项编译代码:

$ 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. 如果您的编译器-std=c++0x ,您也可以尝试使用-std=c++0x

You need to include the header functional . 您需要包含标题functional It is available in C++11 . 它在C ++ 11中提供 If you are still having problems, then your compiler may not support C++11 yet. 如果您仍然遇到问题,那么您的编译器可能还不支持C ++ 11。 Try upgrading. 尝试升级。

你也可以使用boost :: bind:

#include <boost/bind.hpp>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM