how to make sure this.Test() call base class method in base class constructor

  • Thread starter Thread starter Ryan Liu
  • Start date Start date
R

Ryan Liu

Hi,

There is a method Test() implemented in base class and override in subclass.

In base class itself, how to make sure

this.Test() will just call implementation in base class only?

Thanks a lot!
Ryan Liu
 
Ryan,
In base class itself, how to make sure

this.Test() will just call implementation in base class only?

You can't, that would defeat the purpose of virtual methods. Instead
you can move the base class' implementation of the Test method to
another, not-virtual method (say TestImpl). Call TestImpl from from
Test and call TestImpl directly if you want non-virtual behaviour.


Mattias
 
Ryan said:
There is a method Test() implemented in base class and override in subclass.

In base class itself, how to make sure

this.Test() will just call implementation in base class only?

You can not force an implementation in a subclass.

But you can omit the virtual keyword, so they can not
override.

Arne
 

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

Back
Top