virtual function

A

asdf

The derived class can redefine the virtual function in the base class.
So, the derived class can redefine the return type, the parameters
list, and the whole content of the virtual function. The derived class
only need to keep the name of the virtual function.

Is this right? Thanks.
 
B

Bart

asdf said:
The derived class can redefine the virtual function in the base class.

The derived class *overrides* the base class implementation.
So, the derived class can redefine the return type, the parameters
list, and the whole content of the virtual function.

No. If you change the parameters you will hide the base class
implementation. That's not the same as overriding.

Regards,
Bart.
 
N

Nate Barney

asdf said:
The derived class can redefine the virtual function in the base class.

A derived class can *override* a virtual function in a base class.
So, the derived class can redefine the return type,the parameters
list, and the whole content of the virtual function. The derived class
only need to keep the name of the virtual function.

Is this right? Thanks.

No. The function signature must remain the same in both classes. This
includes whether the function is declared const. The one exception is
that an overridden virtual function may have a different return type,
but only a type derived from the original return type.

Nate
 
N

Nate Barney

Nate said:
The one exception is that an overridden virtual function may have a
different return type, but only a type derived from the original
return type.

Actually, this is only true for references and pointers to the
aforementioned types. For more information on this, google for
"covariant virtual function".

Nate
 

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
474,159
Messages
2,570,881
Members
47,418
Latest member
NoellaXku

Latest Threads

Top