Accessing Base Class Function

Hi all,

How do I access the base class function when I'm calling the derived class.

The part I'm struggling is in bold.

Thanks

class MusicalComposition{
public:
MusicalComposition();
MusicalComposition(string titleP,string composerP,char year_writtenP);
};

class NationalAnthem : public MusicalComposition{
private:
string nation;
public:
NationalAnthem();
};

NationalAnthem::MusicalComposition(){
cout << "Hello World";
};
You are treating the base class' constructor as if it were a function. It is not.

1
2
3
4
5
6
7
8
9
class NationalAnthem : public MusicalComposition
{
...
public:
    NationalAnthem() : MusicalComposition()
    {
        //Any additional code goes here.
    }
};


If you don't want the constructor inlined, then leave your class definition as is, but write the constructor like this:

1
2
3
4
NationalAnthem::NationalAnthem() : MusicalComposition()
{
    //Additional code goes here.
}


That should work, I would say. Good luck.
Hi thanks for the reply but I still seem like i can't tackle this problem.

One of the questions ask in assignment is

"Implement the overload constructor for class NationalAnthem by invoking the base class contructor"

When they ask the question like this do they mean i must phrase it like this?

NationalAnthem::NationalAnthem(string name) : MusicalComposition()
{
//Additional code goes here.
}

That sentence doesn't make sense. Is it suppose to be:
"Implement the overload constructor for class NationalAnthem and invoke the base class contructor in its initializer list"

1
2
3
4
NationalAnthem(string titleP,string composerP,char year_writtenP) : MusicalComposition(titleP, composerP, year_writtenP)
{
        //Any additional code goes here.
}

Topic archived. No new replies allowed.