Jump to content
  • Advertisement
Sign in to follow this  
Colin Jeanne

Inheritance Problem (Skipping A Base Class?)

This topic is 4891 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 three abstract classes First those in IConsoleObjects.h
class IConsoleObject : public IManageable {
public:
   // Generic drawing method
   virtual bool Draw(Coord c, IConsole *console) = 0;

   // Convenient overload for the basic drawing method
   virtual bool Draw(sint16 x, sint16 y, IConsole *console) = 0;
};

class IAnimatedConsoleObject : public IConsoleObject {
public:
   // Gets and sets the amount of time per frame, in ms
   virtual uint32 TimePerFrame() = 0;
   virtual void TimePerFrame(uint32 ms) = 0;
};

Then one more in IAnimatedObject.h
// A multiframe object
class IAnimatedObject : public IAnimatedConsoleObject
{
public:
   // Convenient wrapper for another draw function
   virtual bool Draw(std::size_t frame, sint16 x, sint16 y, IConsole *console) = 0;

   // Draws the frame to a coordinate (uses Object's drawing code)
   virtual bool Draw(std::size_t frame, Coord c, IConsole *console) = 0;
};

When I try to use an object that implements IAnimatedObject I am not able to use the Draw() methods from IConsoleObject. MSVC++.NET 2003 tells me that only the Draw() methods from IAnimatedObject are available. However, I am able to use the methods from IAnimatedConsoleObject and even the methods from IManageable! I'm not sure if this affects this but these interfaces live in a static library and I am using a function exported from that library to give me a pointer to an IAnimatedObject.

Share this post


Link to post
Share on other sites
Advertisement
I believe the draw functions in IAnimatedObject are hiding the Draw function in IConsoleObject. When you declare a function in a derived class that has the same name as a function in a base, even if they have different parameters and types, the function in the derived calss will hide the one in the base class. There's a use of the using keyword that allows you to unhide the function, but I'm not sure of the syntax. I'll look it up and get back to you.

Share this post


Link to post
Share on other sites
Here's a description of the problem, as well as a solution. In short, add this to the body of IAnimatedObject:

using IConsoleObject::Draw;



This will work, even though IConsoleObject is an extra level up the inheritance tree (I tested).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!