2013-08-16 60 views
1

我想从Wrox's Professional C++编译这个简单程序TEST.CPP:如何用std :: bind编译C++程序?

#include<iostream> 
#include<functional> 
using namespace std; 

void func(int num, const string& str) 
{ 
      cout << num << ' ' << str << endl; 
} 

int main() 
{ 
    string str = "abc"; 
    auto f = bind(func, placeholders::_1, str); 
    f(16); 
} 

我有G ++(Debian的4.4.5-8)4.4.5 compilator我用它这样的:

g++ -std = c++0x test.cpp -o test 

我得到的错误:

error: no match for call to ‘(std::_Bind<void (*(std::_Placeholder<1>, int)) 
(int, int)>) (int)’ 

为什么程序不能编译?

我无法编译C++ Reference的示例程序。

+3

对我的作品(GCC支持4.8.1)。您可能需要更新您的编译器。 – Rapptz

+0

'apt-get install g ++'后,我收到消息“该程序已经在最新版本”。是否有可能在Debian Squeeze中升级g ++ 4.4? – cpp

回答

3

std::bind是C++ 11,这不是由g ++ 4.4,您需要通过系统升级至少给Debian喘息的G ++ 4.7升级或使用/ etc/apt/preferences中包绑定

+1

GCC在http://gcc.gnu.org/projects/cxx0x.html发布支持的C++ 11功能列表。不幸的是,我找不到包含'std :: bind'函数模板的功能。 – Chris

+0

D'oh,当然我在那里找不到它,因为它不是语言功能,而是库功能。它是libstdC++的一部分,其中列出了它的C++ 11实现状态:http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011不幸的是,它们没有指定版本在哪些功能实现。 – Chris