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 › Combine objects of a Class to form an other Class
Page Index Toggle Pages: 1
Combine objects of a Class to form an other Class (Read 355 times)
Combine objects of a Class to form an other Class
Mar 31st, 2009, 7:34am
 
Hey Processing-community,

the question is: can I combine objects of a certain Class to form a new Class.

In code:
I have a certain amount of objects (of class Node() ) and I want to form a new object, which is a combination of a certain (on forehand unknown number) of Nodes: class NodeCombination().

How do I make the constructor of the class NodeCombination?
I have now the following, which gives a lot of errors:

Code:

class NodeCombination {
int NON;
Node usedNodes[];

NodeCombination(nodes[float numberOfNodes]) {
this.NON = numberOfNodes;
this.usedNodes = nodes[NON];
}

}


Should I first maybe create an arraylist of the Nodes I want to use, and can I than use this arraylist in the declaration of the class NodeCombination?
Re: Combine objects of a Class to form an other Class
Reply #1 - Mar 31st, 2009, 10:36am
 
class NodeCombination
{
 int numNodes;
 Node[] nodes;
 NodeCombination(Node[] _nodes)
 {
   numNodes = _nodes.length;
   nodes = _nodes;
 }
}
Page Index Toggle Pages: 1