"jlopes" <jl*******@COMCAST.NET> wrote in message
news:f1**************************@posting.google.c om...
I'm looking at the differences between these to forms and see no
difference in their use. When accessed through a derived class.
class ABase
{
public:
virtual void filter(){ /* some code */ }
};
class D_of_ABase : public ABase
{
public:
};
class Base
{
public:
void filter(){ /* some code */ }
};
class Child : public Base
{
publc:
};
void main()
{
Child* child = new Child();
D_of_ABase* doab = new D_of_ABase();
child->filter();
doab->filter();
}
Even if you do not override the inherited method, you can still see
diferences if the following conditions are met:
- some class E_ derives from class D_of_ABase and E_ overrides filter()
- you use references or pointers to class D_of_ABase
- you do not initialize the reference or pointer based of objects you
create,
but based of objects you receive from some other module or library
- the other module or library knows or defines class E_ and actualy
provides you
with references/pointers to objects of class E_ (this would be
perfectly legal C++)
then when you would call filter() through your reference/pointer to
C_of_ABase, you
will have the surprise of getting yourself a call to some other override of
filter() then the one in ABase (namely the one form E_).
Should you have used classes Base and Child in my example, you would have no
such surprise.
I think you can still explicitly call (with no surprises) the inherited
version of filter() like this:
D_of_ABase &Dobj = InvokeDObjectFactory() //Get reference to D from
outside
Dobj.ABase::filter() // Explicitly call the base class
override, no matter
// what was provided with the
reference form outside
"Timothy Madden"
Romania