• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Calling vs Overriding

## Recommended Posts

gimp    142
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

##### Share on other sites
Houdini    266
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