473,395 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

deriving a class from a base class

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

Aug 22 '06 #1
1 1361
"markww" <ma****@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
: 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
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com
Aug 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Steven T. Hatton | last post by:
This may be another question having an obvious answer, but I'm not seeing it. I'm trying to create a class that derives from std::valarray<std::string>. I don't need a template, and I haven't come...
8
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
2
by: Julian | last post by:
I would like to have output from my program to be written to cout as well as a file. (actually, i want several other output options but this should explain my problem in the simplest way). I have...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
4
by: Confused Newbie | last post by:
I'm converting an app written in VB 2003 to 2005 and need advice for how to deal with this situation: The app has a number of "manager" classes that handle the data access. They all have...
2
by: m.tyka | last post by:
Hello, I have the following code --- template < typename T> struct Base { T base_member; };
15
by: Nindi73 | last post by:
HI If I define the class DoubleMap such that struct DoubleMap : public std::map<std::string, double>{}; Is there any overhead in calling std::map member functions ? Moreover are STL...
12
by: Shraddha | last post by:
Can I stop people by deriving my class? I mean I don't want my class to be as a base class... Can I do that?
7
by: wangxiaohu | last post by:
I am trying to write a class myVector based on std::vector and add only a sort method. The sort method needs to access the array stored in the base class using iterator. I have following draft...
3
by: Al Grant | last post by:
Consider two translation units, (1): namespace { struct S { }; } struct D: S { virtual int f(void); }; and (2): #include <typeinfo> struct D; char const *f(D *p) { return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.