mangesh wrote:
virtual mechanism is activated on pointers only , not on objects .
what is reason beind this .
It is also "activated" on references, just as well.
The reason is simple. If you have an object, there is no need to
"activate" any "virtual mechanism" because the type is known at the
compile-time. With pointers the "real" type, the type with which
the top-most object was created, is unknown at compilation. Hence
the need (or the capability) to dispatch those calls dynamically.
What I mean is that when you have a pointer (or a reference) to some
class, the compiler thinks that it can be working with a sub-object
of another object, with an object of a base class, whereas the "real"
object is of the derived class. There is a way to know, mind you,
but it involves the same "virtual mechanism", and it's only possible
to know at run-time, not compile time.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask