Calling vs Overriding

Started by
0 comments, last by gimp 22 years, 2 months ago
Background: I have a base class, lets call it CWidget. From that I derive CButton. CWidget has a SetAttributes virtual function that is overidden in CButtons implementation. The function on Cwidget however has some useful common code in it that all derived classes would like to use. Things like Setting the Name, Width and Height attributes. Question: Can I still call the base classes implementation from a derived class, perhaps with some kind of scoping operator to specify that I want to call the base classes copy of the function. Furthermore can I call this from within a derived classes implementation of the same name (calling Cwidget::Setattributes() from Cbutton::SetAttributes) I the alternative is to have a ton of functions with similar tasks, similar names that are called at different times. Currently I just cut-paste the code in to each derived class... Chris Brodie http:\\fourth.flipcode.com
Chris Brodie
Advertisement
Yes, and you can a base class function from a derived class like so:

  void CButton::SetAttributes(){     CWidget::SetAttributes();  // This is a base class function}  



- Houdini
- Houdini

This topic is closed to new replies.

Advertisement