Connecting Tech Pros Worldwide Help | Site Map

Instance creation

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 20th, 2005, 10:15 AM
dave1997_us@yahoo.com
Guest
 
Posts: n/a
Default Instance creation

Hello,
I get the same o/p for the 2 pieces of code below:
Base *b = new Base ;
b->test() ;
delete b ;

vs just saying:
(new Base)->test() ;

In the second case, how is the object created and what instance of the
object do we have to "delete" at the end of the program. It's a very
fundamental thing which I seem to be getting confused at. Inputs are
welcome.

Thanks


  #2  
Old August 20th, 2005, 10:35 AM
Rolf Magnus
Guest
 
Posts: n/a
Default Re: Instance creation

dave1997_us@yahoo.com wrote:
[color=blue]
> Hello,
> I get the same o/p for the 2 pieces of code below:
> Base *b = new Base ;
> b->test() ;
> delete b ;
>
> vs just saying:
> (new Base)->test() ;[/color]

What is an "o/p"?
[color=blue]
> In the second case, how is the object created[/color]

Just the same as in the first case. Dynamically with new.
[color=blue]
> and what instance of the object do we have to "delete" at the end of the
> program.[/color]

Well, you didn't store the pointer to it, so unless Base's constructor or
the test() member function stores it somewhere, that pointer is lost and
you cannot delete the object.

  #3  
Old August 20th, 2005, 10:45 AM
dave1997_us@yahoo.com
Guest
 
Posts: n/a
Default Re: Instance creation

o/p as in output.
[color=blue]
> Well, you didn't store the pointer to it, so unless Base's
> constructor or the test() member function stores it
> somewhere, that pointer is lost and you cannot delete the
> object.[/color]

hmm.. Thanks for the suggestion, I will ponder over it :)

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.