Multiple Inhetitence

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 34
Reputation: g_loughnan is an unknown quantity at this point 
Solved Threads: 0
g_loughnan g_loughnan is offline Offline
Light Poster

Multiple Inhetitence

 
0
  #1
Nov 19th, 2007
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()
{
	cout << Track_Pop.getTrackGenre() << endl
		 << Track_Rock.getTrackGenre() << endl;
}
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 34
Reputation: g_loughnan is an unknown quantity at this point 
Solved Threads: 0
g_loughnan g_loughnan is offline Offline
Light Poster

Re: Multiple Inhetitence

 
0
  #2
Nov 19th, 2007
I just realised that I put in

  1. string Track_Pop::getTrackGenre()
  2. {
  3. return "Pop track";
  4. }

twice. One of those should be:

  1. string Track_Rock::getTrackGenre()
  2. {
  3. return "Rock track";
  4. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC