Jump to content
  • Advertisement
Sign in to follow this  
captacha

Bypassing Copy Constructor

This topic is 2491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!