<分区>
这可能是 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。这样我就可以访问 a in b 的成员。
肯定只是B的调用中的东西 b(&a);也许您可以很容易地找出我的问题所在。