Jump to content
  • Advertisement

Archived

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

SecondBest

Return type relaxation rule

This topic is 5205 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
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
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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!