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"); //
}
總結
以上是生活随笔為你收集整理的c语言prog.c: in function 'main':,C语言 tr1 :: function和tr1 :: bind的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 专插本跨考计算机科学与技术,2021年计
- 下一篇: HP计算机管理软件,惠普电脑硬件诊断工具