Jump to content

  • Log In with Google      Sign In   
  • Create Account


new?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Tac-Tics   Members   -  Reputation: 197

Like
Likes
Like

Posted 28 January 2002 - 10:03 AM

Another newbie question here =-) This one comes from a difference in Java and C++ syntax. In Java, as I understand it, whenever you define an object of a class, you have to use this format: ClassName object1 = new ClassName(int parameter1); But in C++ they have two ways to define an object of a class: className object1(int parameter); and className object1 = new className(int parameter); Why does C++ have 2 ways to do this? What''s the difference between using "new" and not using it? "I''''m not evil... I just use the power of good in evil ways."

Sponsor:

#2 Null and Void   Moderators   -  Reputation: 1087

Like
Likes
Like

Posted 28 January 2002 - 10:27 AM

The version using "new" isn''t limited to the scope of the declaration. It stays on the heap until you use "delete" for that variable. If you don''t call ever delete, you get a memory leak (there''s no garbage collection in C/C++, remember; you have to do it yourself).



#3 Oluseyi   Staff Emeritus   -  Reputation: 1670

Like
Likes
Like

Posted 28 January 2002 - 10:39 AM

The version calling new also returns a pointer to the object, as opposed to creating a "static" local object. The syntax should be ClassName *object2 = new ClassName(parameter);

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!


#4 Tac-Tics   Members   -  Reputation: 197

Like
Likes
Like

Posted 28 January 2002 - 10:47 AM

Much thanks

"I''''m not evil... I just use the power of good in evil ways."




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS