这可能是一个C++初学者的错误,但我真的很迷茫现在得到这个编译器错误:呼叫错误没有匹配的功能,同时将一个指向构造
error: no matching function for call to 'B::B(A (*)())'
note: candidates are: B::B(A*)
我已经写了两个类,看起来简化是这样的:
//a very simple class A
class A
{
public:
A()
{
//do some stuff in Constructor
}
}
//another class, that stores a pointer to an object of A as a field
class B
{
private:
A* _a;
public:
//simply initialize the field in Constructor
B(A* a) : _a(a) { }
void doMagic()
{
//do something with _a
_a->xyz();
}
}
什么我打电话在我的代码是这样的:
A a();
B b(&a); //here the error appears
我想要的是创建一个对象a并将其指针传递给对象b。这样我可以访问b中的成员。
它必须只是在B的呼吁(&一);也许你可以很容易地发现我的问题。
https://en.wikipedia.org/wiki/Most_vexing_parse –