c语言prog.c: in function 'main':,C语言 tr1 :: function和tr1 :: bind

我将以下内容放入Ideone.com(和codepad.org):

#include

#include

#include

struct A {

A(const std::string& n) : name_(n) {}

void printit(const std::string& s)

{

std::cout << name_ << " says " << s << std::endl;

}

private:

const std::string name_;

};

int main()

{

A a("Joe");

std::tr1::function f = std::tr1::bind(&A::printit, &a, _1);

a("Hi");

}

并得到这些错误:

prog.cpp: In function ‘int main()’:

prog.cpp:18: error: ‘_1’ was not declared in this scope

prog.cpp:19: error: no match for call to ‘(A)(const char [3])’

prog.cpp:18: warning: unused variable ‘f’

我不能为我的生活找出第18行的错误.

两个错误:

> _1在命名空间std :: tr1 :: placeholders中定义.你需要使用namespace std :: tr1 :: placeholders;在main()中,或使用std :: tr1 :: placeholders :: _ 1.

>第19行应为f(“Hi”),而不是(“Hi”).

#include

#include

#include

struct A {

A(const std::string& n) : name_(n) {}

void printit(const std::string& s)

{

std::cout << name_ << " says " << s << std::endl;

}

private:

const std::string name_;

};

int main()

{

using namespace std::tr1::placeholders; //

A a("Joe");

std::tr1::function f = std::tr1::bind(&A::printit, &a, _1);

f("Hi"); //

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值