Sign in to follow this  

Interfaces? Java Style in c++?

Recommended Posts

Hey Guys and Gals, I have been working on a small application with a Game class, that is full of GameCharacter objects. Each GameCharacter object will have a pointer to an ActionScript object (myActionScript). The ActionScript is used to define a simple AI for the character, for use like: /* assume GameCharacter has ActionScript *m_myActionScript; is an ActionScript pointer */ /* assume ActionScript::Act() is declared in ActionScript */ Game.gameCharacter1.m_myActionScript->Act(); Now, what I would like to do is to have ActionScript act as a Java-like interface, where I can have other classes that implement it, and then pass these implementing classes around as if they were ActionScript objects. As an example, lets say I had a ActionMonster class defined and it implemented the ActionScript class. I want the GameCharacter object's m_myActionScript member to point to the ActionMonster object, even though they differ in type. And then when Game.gameCharacter1.m_myActionScript->Act(); is used, the ActionMonster::Act() is really called. Is this possible? I would think it is, but I am not sure what would be the best way to approach it. I'd love some help thinking up ways to design this. Thanks, -sevans

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this