当它是类的成员变量时,我在初始化boost::shared_ptr
时遇到问题。我看到了上一个问题:
How to initialize a shared_ptr that is a member of a class?
但是我仍然有编译器错误。快速示例代码:
class A
{
public:
A();
};
class B
{
public:
B();
private:
boost::shared_ptr<A> mA;
foo() {
// the line below generates a compiler error
mA(new A()); // ERROR
// below will work....
boost::shared_ptr<A> tmp(new A()); //OK
mA = tmp;
}
};
编译器抱怨:
error: no match for call to "(boost::shared_ptr<A>) (A*)"
然而,创建一个tmp shared_ptr
,然后将其分配给mA
编译正常。我正在Ubuntu 14.04机器上交叉编译英特尔爱迪生。
我错过了什么?