1

I have the following classes:

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:

};

I would like to have a std::vector container containing std::unique_ptr or std::shared_ptr. so I created one like this:

typedef std::unique_ptr<PacketMember<unsigned char> > prt;
std::vector<prt> v;
v.push_back(prt(new NormalMember<unsigned char>(header)));

but compiler complains about PacketMember<unsigned char> being an inaccessible base of NormalMember<unsigned char>. I've seen people suggesting on this very website to use a poiter / smart-pointer to the base class and then make it point to derived classes. What am I doing wrong here?

Marco A.
  • 43,032
  • 26
  • 132
  • 246
max
  • 2,627
  • 1
  • 24
  • 44
  • @Aesthete I'm sorry, but I don't understand your point. – max Oct 26 '14 at 22:57
  • 2
    `class NormalMember : PacketMember` specifies *private* inheritance. It seems you want *public* inheritance instead: `class NormalMember : public PacketMember` – dyp Oct 26 '14 at 23:01
  • Make `NormalMember` inherit publicly by `PacketMember`. The default is private. – Pradhan Oct 26 '14 at 23:01
  • For the next question, please try to reduce the amount of code to the bare minimum that reproduces the problem: http://stackoverflow.com/help/MCVE – dyp Oct 26 '14 at 23:02
  • 1
    @dyp yes! I can't believe I missed that. Thanks a lot. – max Oct 26 '14 at 23:05
  • @dyp I reduced the code to bare minimum. – max Oct 26 '14 at 23:16
  • Many thanks. The next tip I can give for future questions is to include the exact error message from the compiler. Also, you'll find some similar questions by searching for "inaccessible base" (maybe plus a "C++" context). The first google hit I find is that one: http://stackoverflow.com/q/4847100 – dyp Oct 27 '14 at 00:21

0 Answers0