2013-08-16 57 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