派生模板类的容器

时间:2014-10-26 22:45:17

标签: c++ templates inheritance c++11 smart-pointers

我有以下课程:

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_ptrstd::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指向基类,然后让它指向派生类。我在这里做错了什么?

0 个答案:

没有答案