Inheritance Problem (Skipping A Base Class?)

Started by
2 comments, last by Colin Jeanne 18 years, 9 months ago
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.
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.
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).
That worked perfectly!

This topic is closed to new replies.

Advertisement