• Advertisement
Sign in to follow this  

Interfaces? Java Style in c++?

This topic is 4233 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

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
Advertisement
Being an old Java programmer newly converting to C++, this is a topic I was just researching. I have found the C++ FAQ Lite a great resource. Here is the topic on which you need information: C++ FAQ Lite: Pure virtual methods

Share this post


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

  • Advertisement