Original Post
Hello! I'm using Visual C++ 6.0, and I'm having some strange problems using C++ multiple inheritance and virtual base classes, and hope you can help me (I'm totally confused). See the example below: The problem: when I try to access the some "C_EventHandler" method (eg. "onMouseClick()") from within "C_Window" implementation file, a compiler error is thrown. I have googled for multiple inheritance and virtual base classes and something but found nothing about. Can you show me the correct way to do that? Thanks a lot!
// element.hpp - Virtual base class (element)
class C_Element {
public:
virtual void draw() = 0;
...
}
// eventhandler.hpp - Virtual base class (event handler)
class C_EventHandler {
public:
virtual void onMouseClick();
...
};
// keyhandler.hpp - Virtual base class (keyboard event handler)
class C_KeyHandler : public C_EventHandler {
public:
virtual void onKeyPress( unsigned int );
...
};
// el_window.hpp - GUI window class
class C_Window : public C_Element, public C_KeyHandler {
std::vector<C_Element*> elemVector; // Vector of GUI elements (buttons,
...
};
// el_button.hpp - GUI button class
class C_Button : public C_Element, public C_KeyHandler {
...
}
// el_window.cpp - GUI window implementation file
void C_Window::test() {
cout << "Mouse click detected";
elemVector[elemNr]->onMouseClick(); // <--- ERROR HERE
}
// ERROR: el_window.cpp(226) : error C2039: 'onMouseClick' :
// is not a member of 'C_Element' : see declaration of 'C_Element'