Overriding Question

Hi,
I'm new to C++ and actually used the tutorial here to learn it.
I'm wondering if there is a way to call a function in it's pre-overridden form after it is overridden. For example, say I want to have class draw a rectangle in a draw function. Then say I want to inherit this class and have the new class override the draw function and draw a circle. Is there a way to call the rectangle draw function too? Right now, it's forgetting about the old function, thus losing some of the functionality I wanted to keep.
Thanks,
Sean =)
Last edited on
closed account (z05DSL3A)
Is this what you are looking for?

function overriding
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
//-----------------------------------------------------------------------------
class rectangle
{
public:
    virtual void draw()
    {
        std::cout << "Rectangle" <<std::endl;
    }
};
//-----------------------------------------------------------------------------
class circle: public rectangle
{
public:
    void draw()
    {
        std::cout << "Circle" <<std::endl;
        rectangle::draw();
    }
};
//-----------------------------------------------------------------------------
int main() 
{
    circle c;

    c.draw();

    return 0;
}

Last edited on
Yes! Thank you!
Now I have another question.
It was stated that there were some automatically generated functions such as for copying the class.
How would I reference them? If they are automatically generated, how do I find out what they are?
Sean
The functions you're referring to are probably the copy ctor and assignment operator. These come with built-in default behavior, but can be overridden.

To access them:
1
2
3
4
5
MyClass a;
MyClass b(a);  // copies a to b
MyClass c;

c = a;  // copies a to c 
Last edited on
closed account (z05DSL3A)
Excuse my pedantry, but it is Overriding not Overloading.
you are correct. My mistake! *edits*
Topic archived. No new replies allowed.