Home All Groups Group Topic Archive Search About

diff between virtual and abstract?

Author
8 Sep 2006 7:33 AM
chandu
hello,

what is the difference to use the keyword virtual,abstract when we are
overriding the methods.instead of abstract shall we use virtual everywhere
when we need to override?
i am little confusing to use these keywords.

thaks..

Author
8 Sep 2006 7:56 AM
Marc Gravell
If a subclass *needs* to override a member (i.e. you can't specify a
meaningful body in the base class, as it can't be defined), then it should
be abstract in the base-class; if you just want to give the subclass the
*ability* to override a method (if they want) then it should be virtual. Any
abstract member forces the entire class to be abstract, which also means you
can't create actuall instances of the base class, but you can of the
superclass.

Does that make sense?

Marc
Are all your drivers up to date? click for free checkup

Author
8 Sep 2006 7:58 AM
S³awomir_Pa¶ko
chandu napisa³(a):
> hello,
>
> what is the difference to use the keyword virtual,abstract when we are
> overriding the methods.instead of abstract shall we use virtual everywhere
> when we need to override?
> i am little confusing to use these keywords.
>
> thaks..
>
>
You must (sic!) override when you deriving from abstract class. You can
override metods (if for some reason you need to do something else) when
you deriving from virtual. ;)

best,
Slawomir
Author
8 Sep 2006 2:29 PM
Stoitcho Goutsev (100)
chandu,

In some cases you cannot provide a implementation for some methods, but
method have to be there because it is part of the class interface. You want
the programmers using the class to provide this implementation and you don't
want to let them instantiate objects of this class because without this
method it won't simply work. In this case you declare the method and the
class as abstract. Abstract classes cannot be instantiated because they are
not complete.

In other cases you can provide a default implementation of a method which is
good enough to make the control work even if not re-defined, but you want to
give the programmers using your class as a base class to provide their
better implementation. In this case you declare the method as virtual thus,
giving the progammers options whether to use the default or provide their
own eomplementation or if they which to use the default and tweak the
results.


--
HTH
Stoitcho Goutsev (100)

Show quoteHide quote
"chandu" <nareshv_chan***@hotmail.com> wrote in message
news:OlyJkkx0GHA.4016@TK2MSFTNGP02.phx.gbl...
> hello,
>
> what is the difference to use the keyword virtual,abstract when we are
> overriding the methods.instead of abstract shall we use virtual everywhere
> when we need to override?
> i am little confusing to use these keywords.
>
> thaks..
>



Post Thread options