On Wed, 17 Oct 2007, Mohan S N wrote:
>> 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;
> }
Why would I not just do
der *d;
d=new der();
...
..
.
That way I'd have access to d->der_var whereas b->der_var would be out of
scope. Is it a question of overhead in allocating the pointer?
cheers,
Jacob