deriving a class from a base class

M

markww

Hi,

I have this class:

class CBase {
int m_nData;
OnStart();
OnRightMouseClick();
}

I want to derive another class from it and keep all its functions the
same, but I want to override OnRightMouseClick() with its own code:

class CNew : public CBase {

OnRightMouseClick(); // CNew specific code in here.
}

Is that possible, how do I do it?

Thanks as always
 
I

Ivan Vecerina

: Hi,
:
: I have this class:
:
: class CBase {
: int m_nData;
: OnStart();
: OnRightMouseClick();
You forgot to specify the mandatory return types.
Also if you want to override the functions in a subclass,
you need to declare them as virtual in CBase.
So:
virtual void OnStart();
virtual void OnRightMouseClick();
: }
:
: I want to derive another class from it and keep all its functions the
: same, but I want to override OnRightMouseClick() with its own code:
:
: class CNew : public CBase {
:
: OnRightMouseClick(); // CNew specific code in here.
Instead: virtual void .... [ virtual is optional here ]
: }
:
: Is that possible, how do I do it?
Given the above:
void CNew::OnRightMouseClick()
{
//....
CBase::OnRightMouseClick(); // if you wish to call the base class
}

: Thanks as always

hth -Ivan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top