Jump to content
  • Advertisement

Archived

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

LinaInverse2010

Inheretence Question

This topic is 5371 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

I have a base class with this code:

class PktFlt
{
public:
...

	// PktFlt Operations

	void operator+=(const PktFlt &rhs);

...

};

and another class:
class PktVec : public PktFlt
{
public:
...
         void operator+=(const Vec &rhs);
...
};
When, on the second class, I use the += operator with the PktVec class I get a conversion error in VS .Net because it doesn''t find the += operator from the base class. But when I take out the overloaded one in the inherented class, it works fine. Shouldn''t it inherit the +=(const PktFlt &rhs) function? LinaInverse

Share this post


Link to post
Share on other sites
Advertisement
You've now encountered the wonderful world of name hiding. When you have a function in a derived class with the same name as a function in the base class with a different function signature, it hides all the instances of the function in the base class. To fix, try a using directive. e.g.:

class PktFlt {
public:
void operator+=(const PktFlt &rhs) {}
};

class PktVec : public PktFlt {
public:
using PktFlt::operator+=;
void operator+=(const Vec &rhs) {}
};

Keep in mind that PktVec does inherit PktFlt's operator+=() function despite hiding it, so even without the using directive, code like this will still work:

PktFlt a;
PktVec b;
b.PktFlt::operator +=(a);


edit: bad grammar

[edited by - SiCrane on March 7, 2004 7:24:13 PM]

Share this post


Link to post
Share on other sites
... Is there are reason why PktVec::operator+= doesn''t take a PktFlt& for its argument? IOW, why are you hiding the name? Oh, you wanted to be able to add both types? Hmm. How is the Vec type related (if at all) to PktFlt and PktVec?

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!