+ Reply to Thread
Results 1 to 2 of 2

Thread: How can I call function of base class with derived class object?

  1. #1

    How can I call function of base class with derived class object?

    How can I call function of base class with derived class object?

    Help.

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    109
    You can use . and :: operator for this.

    Example:

    Code:
    class CBase
    {
    public:
    	CBase()
    	{
    		
    	}
    
    	virtual void DisplayMessage()
    	{
    		OutputDebugString("Hello from CBase::DisplayMessage\n") ;
    	}
    } ;
    
    class CDerived : public CBase
    {
    public:
    	CDerived()
    	{
    		
    	}
    
    	virtual void DisplayMessage()
    	{
    		OutputDebugString("Hello from CDerived::DisplayMessage\n") ;
    	}
    } ;
    
    void UseDrivedClass()
    {
    	CDerived objDerived ;
    	objDerived.CBase::DisplayMessage() ;
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

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