On Wed, 17 Oct 2007, Mickey Mathieson wrote:

> --- Jacob Lund Fisker <[EMAIL PROTECTED]> wrote:
>
>> Could someone tell me why/how it is possible to
>> declare a pointer to a
>> base class and use that pointer to declare and point
>> to an object an
>> inherited (larger) class on the heap.
>>
>> I guess my question is what exactly gets allocated
>> on the heap in this
>> case? Is it an "Under" object or an "Over" object?

>>    cout << "Test access to objects on the heap ----
>> pUnder to Over object
>> --- why does this work?" << endl;
>>    pu = new Over;
> Are you asking why it compiles?
>

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?!

Reply via email to