Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: delete [] o...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 13 Topic 45621 of 47032
Post > Topic >>

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.
 




 13 Posts in Topic:
delete [] of Derived objects through Base object which has virt
"subramanian100in@[E  2008-04-28 19:32:38 
Re: delete [] of Derived objects through Base object which has
Sam <sam@[EMAIL PROTEC  2008-04-28 22:49:23 
Re: delete [] of Derived objects through Base object which has
"Jim Langston"   2008-04-28 22:14:10 
Re: delete [] of Derived objects through Base object which has
Kai-Uwe Bux <jkherciue  2008-04-29 02:30:39 
Re: delete [] of Derived objects through Base object which has
James Kanze <james.kan  2008-04-29 02:38:59 
Re: delete [] of Derived objects through Base object which has v
"Jim Langston"   2008-04-29 02:48:22 
Re: delete [] of Derived objects through Base object which has v
"Jim Langston"   2008-04-29 03:05:02 
Re: delete [] of Derived objects through Base object which has
"subramanian100in@[E  2008-04-29 04:52:10 
Re: delete [] of Derived objects through Base object which has
Barry <dhb2000@[EMAIL   2008-04-29 19:58:50 
Re: delete [] of Derived objects through Base object which has
xavier <xavier>   2008-05-13 00:04:19 
Re: delete [] of Derived objects through Base object which has
Ian Collins <ian-news@  2008-05-13 10:06:11 
Re: delete [] of Derived objects through Base object which has
James Kanze <james.kan  2008-04-29 05:45:51 
Re: delete [] of Derived objects through Base object which has
James Kanze <james.kan  2008-05-13 01:53:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 15:57:35 CDT 2008.