0

Hi all,

Just have a curiosity about multiple inheritance. I have defined two classes, each of which returns a string to described an object of that class. I have also made another class which inherits from both of the above classes. I want to define a function in the derived class to output both of the strings from the base classes. This is

class Track_Rock
{
public:

	string getTrackGenre();
};

class Track_Rock
{
public:

	string getTrackGenre();
};

class Track_PopRock: public Track_Rock, public Track_Pop
{
public:

	void combinedGenre();
};

string Track_Pop::getTrackGenre() 
{ 
	return "Pop track";
}

string Track_Pop::getTrackGenre() 
{ 
	return "Pop track";
}

void Track_PopRock::combinedGenre()
{
	[B]cout << Track_Pop.getTrackGenre() << endl
		 << Track_Rock.getTrackGenre() << endl;[/B]
}

I get an error: "error C2275: 'Track_PopRock::Track_Pop' : illegal use of this type as an expression".
Could anyone suggest a way of outputting the genre of the two base classes in the derived class?
Thanks,
G.

1
Contributor
1
Reply
2
Views
9 Years
Discussion Span
Last Post by g_loughnan
0

I just realised that I put in

string Track_Pop::getTrackGenre() 
{ 
	return "Pop track";
}

twice. One of those should be:

string Track_Rock::getTrackGenre() 
{ 
	return "Rock track";
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.