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.
Page Index Toggle Pages: 1
PTR (Read 355 times)
PTR
Mar 16th, 2009, 8:51am
 
Hello ladies & gentlemen,how can I make use of pointers in processing IDE just like we do in C++ or so?Thank you for your answers.
Re: PTR
Reply #1 - Mar 16th, 2009, 10:36am
 
I think you ask the wrong question.
You should explain instead what you want/need to do, and we will explain how to do it in Java (Processing).

In short, there are no pointers in Java, the nearest thing is object references.
Re: PTR
Reply #2 - Mar 16th, 2009, 1:29pm
 
I'm sorry to cause you such trouble,but I mean to make a tree-like structure of pictures,say,to make a tree whose nodes are pictures.How to?Thank you for your attention.
Re: PTR
Reply #3 - Mar 16th, 2009, 1:39pm
 
You can do it quite easily. You pass objects by reference by default, and so you can put the references in an array or assign them to local names etc easily.

Code:
class node
{
node[] children;
PImage img;
node(PImage _img)
{
img=_img;
}

void addChild(node n)
{
children=(node[])append(n,children);
}
}
Thank you,but a few problems remained
Reply #4 - Mar 17th, 2009, 4:38am
 
I made the test below:
node n1;
int i;
node nodenew;

void setup()
{
 size(200,200);
 n1=new node(1);
}

void draw()
{

}

void mouseClicked()
{
 nodenew=new node(2);
 n1.addchild(nodenew);
 n1.pt();

}

class node
{
 node[] children;
 int count;
 node(int _count)
 {
   count=_count;
 }
 
 void addchild(node n)
 {
   children=(node[])append(n,children);
 }
 void pt()
 {
   println(this.count);
 }
}

then I have error messages:
Exception in thread "Animation Thread" java.lang.IllegalArgumentException: Argument is not an array
at java.lang.reflect.Array.getLength(Native Method)
at processing.core.PApplet.append(PApplet.java:4715)
at picnude$node.addchild(picnude.java:50)
at picnude.mouseClicked(picnude.java:35)
at processing.core.PApplet.handleMouseEvent(PApplet.java:1609)
at processing.core.PApplet.dequeueMouseEvents(PApplet.java:1539)
at processing.core.PApplet.handleDraw(PApplet.java:1434)
at processing.core.PApplet.run(PApplet.java:1328)
at java.lang.Thread.run(Thread.java:619)

It seems confusing,please help!Thank you again!
Re: PTR
Reply #5 - Mar 17th, 2009, 10:07am
 
Oops, I may have got the arguments to append the wrong way round, try (node[])append(children,n);
Page Index Toggle Pages: 1