Hi,
Here is a question that is best suited by example:
Display All
As you can see "CGhost" inherits all the 'properties'
from IActor as well as CPlayer with the addtion of
a method called "SetName(..)".
Now then, when I want to add an print out my list of
actors
Display All
But, now I want to check and see if it is adding my actors
to my list. The problem is '"GetName(..)" is not part of IActor'. Is there a way of getting around this problem
with out having to write a pure method for "SetName(..)" in IActor? Logically it does not make sence
to do it since IActor is a "generic" player, (which is my only option right now.)
Here is how I add either a ghost or player to a std map.
Thanks again guys
Sabrina
Here is a question that is best suited by example:
Source Code
- class IActor
- {
- u_long m_ID;
- u_int x;
- public:
- virtual SetID( u_long ID ) = 0;
- virtual u_long GetID( void ) =0;
- virtual void SetPositionX( uint PosX ) = 0;
- virtual uint GetPositionX( void ) = 0;
- // and some more methods.
- };
- class CGhost : public IActor
- {
- SetID( u_long ID );
- GetID( void );
- void SetPositionX( uint PosX );
- uint GetPositionX( void );
- }
- class CPlayer : public IActor
- {
- SetID( u_long ID );
- GetID( void );
- SetName(std::string PlayerName ); // NEW
- void SetPositionX( uint PosX );
- uint GetPositionX( void );
- }
As you can see "CGhost" inherits all the 'properties'
from IActor as well as CPlayer with the addtion of
a method called "SetName(..)".
Now then, when I want to add an print out my list of
actors
Source Code
- PrintActorList( void )
- { shared_ptr<IActor> p;
- for ( ActorMap::iterator x = m_ActorMap.begin(); x != m_ActorMap.end(); x++ )
- {
- p = GetActor( x->first );
- ulong id = p->GetID();
- switch ( id )
- { // Pacman.
- case 0 : { std::string s = p->GetName();
- wsprintf(ErrorBuff, "Player Type %d, Player Name: %s.\n", p->GetID(), s.c_str() );
- break;
- }
- // Ghost.
- case 1 : { wsprintf(ErrorBuff, "Player Type %d, Ghost.\n", p->GetID() );
- break;
- }
- }
- MessageBox(NULL, ErrorBuff ,"Error",MB_OK);
- }
But, now I want to check and see if it is adding my actors
to my list. The problem is '"GetName(..)" is not part of IActor'. Is there a way of getting around this problem
with out having to write a pure method for "SetName(..)" in IActor? Logically it does not make sence
to do it since IActor is a "generic" player, (which is my only option right now.)
Here is how I add either a ghost or player to a std map.
Thanks again guys
Sabrina