CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    20

    A question on Pointers and inheritance

    Hi guys,

    I am doing a project for my mid term and I am held up with this doubt. I might have misunderstood something all together or it might be a small mistake. Please point it out:

    I have a baseentity class defining the features of a character.
    I have three entities TEnt, Male and Female which inherits from the base entity.
    Now what I wanted was to have a Entitymanager Class which manages all the entities.

    This is a code I wrote for my entity manager:
    namespace Sims{
    /*! Forward declaration of the class*/
    class TEnt;


    /*! class Entity manager inherits from the singleton_client class */
    class EntityManagerrivate Singleton_client{
    /*! \class Sims::EntityManager "include/EntityManager.h" <BR>
    \brief A Singleton manager entity that basically manages all the entities in the scene
    Inherited from the SEntityEyeDefs
    */
    public:
    /*! A class that registers the entity to the base vector*/
    /*! FIXME: This function needs to be defined for every class of entity*/
    void REGISTER_ENTITY_INSTANCE(TEnt& instance);




    /*! Prints out a test message //TODO: needs to be removed after testing */
    void print();

    private:
    /*! A vector of Each of the classes */
    //FIXME: This piece of code is rubbish.. i need to have a access to all the entities rather than a vector of every set of entity
    /*! A vector of TEnts*/
    std::vector < TEnt* > m_ppTEntList;

    };
    }

    As you can see here there needs to be a private member variable for every class that inherits from the base entity . Also Every function like the REGISTER which has a input or output of the class needs to be called for each and every class. I can understand that this is bad coding. Is there a better way to do this at all?
    |

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: A question on Pointers and inheritance

    Quote Originally Posted by sundar0206 View Post
    As you can see here...
    That's the problem -- it is very difficult to "see", since you didn't use code tags when posting your code. Please do so.

    Second, there is nothing specific to Visual C++ in that code, so you should have posted this in the non-Visual C++ forum.

    Regards,

    Paul McKenzie

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

    Re: A question on Pointers and inheritance

    As Paul said, that code's impossible to read without code tags and with code almost indistinguishable from comments. I imagine you're getting this from your teacher but me comments like this just get in the way.
    Code:
    /*! Forward declaration of the class*/
    class TEnt;
    It's easy to see it's a forward declaration. The comment adds nothing but clutter.

Tags for this Thread

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