gpt4 book ai didi

c++ - 如何使用 std::bind 编译 C++ 程序?

转载 作者:行者123 更新时间:2023-11-30 01:57:45 25 4
gpt4 key购买 nike

我想从 Wrox's Professional C++ 编译这个简单的 test.cpp 程序:

#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 编译器,我是这样使用它的:

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 的示例程序

最佳答案

std::bind 是C++11,g++ 4.4 不支持你至少需要升级到Debian Wheezy 的g++ 4.7 系统升级或使用/etc/apt/preferences 包绑定(bind)

关于c++ - 如何使用 std::bind 编译 C++ 程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18266575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com