我有以下课程:
template <typename T>
class PacketMember
{
public:
PacketMember() { }
// Some non-virtual member functions
};
template <typename T>
class NormalMember : PacketMember<T>
{
public:
};
template <typename T>
class CheckSumMember : PacketMember<T>
{
public:
};
我希望std::vector
容器包含std::unique_ptr
或std::shared_ptr
。所以我创建了一个这样的:
typedef std::unique_ptr<PacketMember<unsigned char> > prt;
std::vector<prt> v;
v.push_back(prt(new NormalMember<unsigned char>(header)));
但是编译器抱怨PacketMember<unsigned char>
是NormalMember<unsigned char>
无法访问的基础。我已经看到人们建议在这个网站上使用poiter / smart-pointer指向基类,然后让它指向派生类。我在这里做错了什么?