Thread: Someone help me a bit here. [ inheritance ]

  1. #1
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001

    Someone help me a bit here. [ inheritance ]

    class CEntity {
    	CEntity ();
    	virtual	   ~CEntity ();
    	void	   calc_dmg (CEntity &obj);
    class CPlayer : public CEntity {
    class CBattlePlayer : public CPlayer {
    class CEnemy : public CEntity {
    Now say I have:

    CEnemy monster;
    CBattlePlayer player;

    can I call player.calc_dmg (monster)?
    How is inheritance aligned with polymorphism, or is it not? Heh...

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    As long as the function was declared public in the base class then yes you can call it from a derived object. Or you can override it in your derived class and have that function call it by using the base class name the scope operator( :: ) and the function using ur example it would be:

    void CBattlePlayer::calc_dmg(CEntity& obj)
    { CEntity::calc_dmg(CEntity);
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 32 bit to 64 bit Ubuntu
    By Akkernight in forum Tech Board
    Replies: 15
    Last Post: 11-17-2008, 03:14 AM
  2. Copy bit to bit
    By Coder2Die4 in forum C Programming
    Replies: 15
    Last Post: 06-26-2003, 09:58 AM
  3. Bit manipulation
    By pkalluri in forum C++ Programming
    Replies: 5
    Last Post: 05-12-2003, 07:06 AM