--- Jacob Lund Fisker <[EMAIL PROTECTED]> wrote:
> On Wed, 17 Oct 2007, Mickey Mathieson wrote:
>
> >> Yes. And also, which object on the heap is pu
> >> pointing to? It seems to me
> >> that pointers that are declared to point to a base
> >> class should not be
> >> able to point to inherited classes too without
> >> problems with e.g. pointer
> >> arithmetic?!
> >>
> > a pointer to a derived class is type-compatible with a
> > pointer to its base class. Polymorphism.
> >
> > The pu pointer is pointing to the Over object.
>
> Yet it can't access any methods in Over that aren't in Under, right?
> So
> what is the point of doing that? I just can't see what the benefits
> are of
> syntactically allowing it in the first place?!
So that you can do this:
class base
{
int var;
public:
base()
{
cout << "In base class constructor\n";
}
};
class der:public base
{
int der_var;
public:
der()
{
cout << "In derived class constructor\n";
}
};
int
main(void)
{
base* b;
b=new base();
delete b;
b=new der();
delete b;
return 0;
}
Regards,
Mohan S N
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com