我无法使用 g++ 4.1.2 编译以下代码:
#include <memory>
class A
{
public:
};
std::auto_ptr<A> GetA()
{
return std::auto_ptr<A>(new A);
}
class B
{
B(std::auto_ptr<A>& pA)
{
}
};
class C : public B
{
C() : B(GetA())
{
}
};
我得到:
将类型的右值表达式无效
std::auto_ptr<A>
转换为类型std::auto_ptr<A>&
问题是我无法定义变量并传递它的引用,因为我在初始化列表中。
当我只被允许改变班级时,我该怎么做C
?