I'm trying to get something to work that is trivial in Java (which is what I code in most of the day at work), but I can't seem to get it to work in C++...
What I want to do is have a class, CScreen, that I will inherit from to create classes for specific screens in my game.
What I'd like to be able to do is have a variable,
CScreen* currentScreen;
defined in my program, and then be able to do:
currentScreen->mainDraw();
where mainDraw() will be the main drawing function called to draw every frame, as an example.
Obviously, as currentScreen is changed to point to a different CScreen-derived class, I still want to be able to call it's mainDraw() function. In other words, I want to do the equivalent of this Java snippet:
class CScreen {
public void mainDraw() { }
}
class mainMenu extends CScreen {
public void mainDraw() { }
}
public class test {
public static void main(String args[]) {
CScreen currentScreen;
currentScreen = new mainMenu();
currentScreen.mainDraw();
}
}
See, simple polymorphism, but I'm not clear on how to implement that in C++. Any help? Thanks all!