How to restrict overiding a function in derived class?

P

Pankh

Hi,

Is it possible to restrict overiding a function in derived class?
To be more clear, I have base class with function foo() and I do not
want any derived class to implement foo() again. Always base version
of foo() should be called on any derived class object. Can I do that?

Thanks.
 
N

Nicolas Pavlidis

Hi,

Is it possible to restrict overiding a function in derived class?
To be more clear, I have base class with function foo() and I do not
want any derived class to implement foo() again. Always base version
of foo() should be called on any derived class object. Can I do that?

No, sorry. You have to write it into your documentation, that this
method must not be overridden.

Kind regards,
Nicolas
 
T

Tom Widmer

Hi,

Is it possible to restrict overiding a function in derived class?
To be more clear, I have base class with function foo() and I do not
want any derived class to implement foo() again. Always base version
of foo() should be called on any derived class object. Can I do that?

From your specific description, just make foo non-virtual.

Tom
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top