Re: delete [] of Derived objects through Base object which has virtual
by Ian Collins <ian-news@[EMAIL PROTECTED]
>
May 13, 2008 at 10:06 AM
xavier wrote:
> Barry wrote:
>>
>> class Base
>> {
>> public:
>> virtual ~Base() {}
>> };
>>
>> class Derived : public Base
>> {};
>>
>> int main()
>> {
>> Base* p = new Derived(); // static type of p is "pointer to Base"
>> // dynamic type of p is "pointer to Derived"
>> }
>>
>
> Hello,
>
> in the above example, what will happen if we add 'delete p;' at the end
> of main(). What will be deleted ? Only the base class part or both base
> and derived part of instantied object ?
>
Both.
--
Ian Collins.