CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2019
    Posts
    8

    Polymorphism Issues

    Hi

    I have class called BaseEntity. I also have a class Entity that inheritse from that. Then I have a class WalkingEntity that inherits from Entity. Then I have a class called IntelligentEntity that inherits from WalkingEntity.I also have a class called EntityFactory that is supposedd to take in a message and return one of these Entity types.

    This is my factory:

    .
    Code:
                //execute the arbitration results
                Advisor v = arbitrationer.decide(arbitration_list);
                //assigns an entity to the Advisor
               
                
                
                
                switch(v.m.event)
                {
                    case BASE_ENTITY:
                        v.e = new BaseEntity;
                        break;
                    case ENTITY:
                        v.e = new Entity;
                        break;
                    case WEAPON_ENTITY:
                        v.e = new WeaponEntity;
                        break;
                    case WALKING_ENTITY:
                        v.e = new WalkingEntity;
                        break;
                    case INTELLIGENT_ENTITY:
                        v.e = new IntelligentEntity;
                        break;
                    case EMPTY_PAWN:
                        v.e = new EmptyPawn;
                        break;
                    case PLAYERCHARACTER:
                        v.e = new PlayerCharacter;
                        break;
                    case STATIC_MESH:
                        v.e = new StaticMesh;
                }
                */
    And advisor looks like:
    Code:
    class Advisor
    {
    public:
        Message m;
        BaseEntity e;
        float weight;
    };
    And a message looks like;

    Code:
    class Message
    {
    public:
        BaseEntity entity;      //FSM to use
        PlayerInputEnum event;    //messages payload
        
        void* payload;    //dependent upon the event type. will look at this pointer
                           //for payload information
        int priority;   //used to calculate scheduling. 0 is immediately , 5 is slower, etc.
        void load_entity();   //loads an FSM into Base Entity entity;
    };
    I would like to use the factory to generate types of entities. But the code above - the inhertiance is all wrong. I just need to be able to populate the BaseEntity field of the Message class, with any of the Entity classes (WALKING_ENTITY) for examples.
    Does that make sense?

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Polymorphism Issues

    entity is an object. It needs to be a pointer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured