Jump to content

  • Log In with Google      Sign In   
  • Create Account


Bypassing Copy Constructor


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
2 replies to this topic

#1 Captacha   Members   -  Reputation: 141

Like
0Likes
Like

Posted 15 February 2012 - 06:28 AM

I'm going to be learning Java soon, so I was wondering about the parameters for functions. In C++ I always used pointer when I wanted to directly affect a variable or object from a function. I've heard Java doesn't have pointers, so how will I be able to do this?

Sponsor:

#2 Chris_F   Members   -  Reputation: 2189

Like
0Likes
Like

Posted 15 February 2012 - 06:35 AM

In Java, all objects are references and exist on the heap. You don't have the choice of constructing objects on the stack or on the heap as you do with C++. If you want to actually perform a deep copy of an object rather than simply creating a secondary reference to it, you have to explicitly clone the object. Also keep in mind that when you pass an object to a function, the reference is passed by value.

#3 SeiryuEnder   Members   -  Reputation: 199

Like
0Likes
Like

Posted 15 February 2012 - 06:36 AM

Read this for a full explanation.

I'm not a Java guru, but the general idea is that it implicitly passes a reference to an object, and the args are pointers to the input.

-edit
Beaten to the punch, it would seem.




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