We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › cloning an object
Page Index Toggle Pages: 1
cloning an object (Read 465 times)
cloning an object
Mar 9th, 2009, 10:19pm
 
Hey fellows,

somehow ;-) i'm not able to clone a simple object

</code>
void draw()
{
PVector v1, v2;
v1 = new PVector(10, 20);
v2 = (PVector) v1.clone();
}
</code>

"The method clone() from the type Object is not visible." is all Processing is saying to me.

Any ideas how to create a duplicate of an object?

thx in advance
viktor

Re: cloning an object
Reply #1 - Mar 9th, 2009, 11:52pm
 
clone isn't magic, it has to be defined (implemented) for a given class.
PVector is very simple, it is easier to do:

v2 = new PVector(v1.x, v1.y);
Re: cloning an object
Reply #2 - Mar 10th, 2009, 4:59pm
 
or
Code:

v2 = v1.get();
Re: cloning an object
Reply #3 - Mar 10th, 2009, 5:35pm
 
Ah? Indeed!
I notice the corresponding reference page has a misleading line: v2 = new PVector(); should be dropped. I would even add something like v1.x = 50.0; after the get to show the two vectors are independent.
Page Index Toggle Pages: 1