• Advertisement

Archived

This topic is now archived and is closed to further replies.

Return type relaxation rule

This topic is 5030 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all; I wrote the following code:
class Base
{
public:

	virtual Base*	someFunc(); 
};

class Derived
{
public:

	virtual Derived*	someFunc(); 
};
 
The compiler (I am using VC++) complained about the difference in return type. However, "The C++ Programming Language" ( 3rd edition ) claims it is perfectly acceptable in case the new returned type is a subclass of the original. So do I misunderstand the rule? Is the compiler ( or the book) wrong? Is there some hidden switch I have to turn on to get this code to work? Peace Out!

Share this post


Link to post
Share on other sites
Advertisement
Did you compile it without the ''*''s?
I''ve never heard of a pointer to a function virtual member. Is that even legal?

// Last Attacker \\---=( LA )=---// LA Extreme \\

ICQ Number : 120585863

E-mail: laextr@icqmail.com

Share this post


Link to post
Share on other sites
These are not "a pointer to a function virtual member" whatever, that is.

These are virtual functions that return pointers to some objects.

Peace Out!

Share this post


Link to post
Share on other sites
quote:
Original post by Last Attacker
Did you compile it without the '*'s?
I've never heard of a pointer to a function virtual member. Is that even legal?



What are you talking about? It's just virtual functions returning pointers to objects of type base or derived.

As for the original question, I'm not sure about that, without looking it up, so I can't answer at the moment.

Edit: Changed class to object, it returns a pointer to a object, not a class of course



[edited by - fredizzimo on April 15, 2004 6:21:40 AM]

Share this post


Link to post
Share on other sites
The code is fine, and it compiles fine in VC++ 2003.NET.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
vc6 doesn''t support co-variant return types. look it up

Share this post


Link to post
Share on other sites

  • Advertisement