请参阅下面代码中的示例,在 B 类中。我做错了什么,记忆明智吗?
我遇到了之前没有的分段错误......
class Obj
{
};
class ObjDerived : public Obj
{
};
template <typename T>
class A
{
public:
Obj<T> *pObj;
public:
A(Obj<T>* pO) : pObj(pO) {}
void doSomethingWithObj()
{ pObj->print(); }
};
template <typename T>
class B : public A<T>
{
public:
B() : A<T>(&o), o(ObjDerived<T>(1.0)) {}
void doSmthg()
{ (this->pObj)->print(); }
public:
ObjDerived<T> o;
};