One of our classes provides tr1::function callback object. When I try assigning a member function to it, though, I get a compiler error.
以下例子未经测试,只是为了说明:
Foo.h:
class Foo()
{
public:
Foo();
std::tr1::function<void (int x)> F;
}
Bar.h:
class Bar()
{
public:
Bar();
Foo* foo;
void HookUpToFoo();
void Respond(int x);
}
Bar.cpp:
Bar()
{
this->foo = new Foo();
this->HookUpToFoo();
}
void Bar::HookUpToFoo()
{
this->foo->F = &Bar::Respond; // error
}
void Bar::Respond(int x)
{
// do stuff
}
The compiler error we get refers to a line in xrefwrap and is Error 1 error C2296: .* : illegal, left operand has type int C:Program FilesMicrosoft Visual Studio 9.0VCincludexrefwrap 64
。 在指派代表方面,我做了哪些错误? 我想走更现代的道路,使用:功能而不是功能点。