0

I am trying to build a list of games that I have. I have a class named gameCommon

class gameCommon
{
public:
string name;
int price;
}

This is the common information all games have. Now the next part is to build another class which will hold information based on what type of game is it? (CD/DVD, Cartridge, etc.)

if CD/DVD, class will be something like this,

class childClassOf_gameCommon
{
public:
int NumOfDisks;
}

etc.But the thing is, the list itself will be inside a vector of the parent class. Something like vector<gameCommon*>. So how do I derive childClassOf_gameCommon so that the list of vector<gameCommon*> will hold the attributes of gameCommon and depending on the type, additional information like numOfDisks.. Sorry for being confusing.

1 Answers1

4

Like this:

class Derived : public gameCommon
{
public:
    int NumOfDisks;
    // ....

A pointer of type gameCommon* can legitimately point to a Derived.

(But as the comments point out, you should try to learn a bit more theory. Learning by doing is good, but you need to know more of the basics, or you'll find it an uphill struggle.)

RichieHindle
  • 272,464
  • 47
  • 358
  • 399