Array List

Not sure how this translates from java to c++. Is there a ArrayList to handle object adding and subtracting?

ArrayList a = new Array();

a.size();
a.add(object);
a.remove(object);

Thanks, T

yes, there is the standard template library. and the vector class:
http://www.sgi.com/tech/stl/Vector.html

more here:
http://www.sgi.com/tech/stl/

best
joerg

Thanks

This is a second question to the ArrayList class. I want to be able to build a global Arraylist so that I can access it in any other particle. Not sure the best way to go about doing this.

i usually don’t do a global variable but a static attribute of a class.
like this:

  
  
// xyz.h  
class xyz  
{  
  static vector<int> globalNumbers;  
public:  
   void doSomethingWithTheNumbers(); // if it doesn't access non-static attributes it could also be declared as static  
};  
  
// xyz.cpp  
vector<int> xyz::globalNumbers; // this is necessary to initialize/call constructor of the static attribute  
  
void xyz::doSomethingWithTheNumbers();  
{  
...  
}  
  

hmm I think im not sure how to ask the question. I drew a picture any help would be great. I am trying to make it so that one particle system (arraylist) can add particles to another particle system (array list).

I think the answer is a pointer ref to the other array list. not sure how to do that :slight_smile:

http://farm3.static.flickr.com/2059/2229321574-4f438af0b3-b.jpg

I am not exactly sure what you are trying to do but the following might help:

One of the nice things about using stl containers is that you can pass them around as references. Typically if you trying to operate on any stl container (in your case a vector) the signature of the method would look like this:

void doSomethingToParticals( vector& particles );

Similarly you can have a list of particle systems and pass them around:

void doSomethingToParticalSystems( vector& psys );

(If you don’t use the little ‘&’ they will be copied on each pass.)

hope that helps,

one quick little tip is to use instead of , just personal preference.

but perhaps more to your question, have you thought about making a static instance of your testApp.cpp (or whatever you’ve named it) and including it in whatever your particle class is? then you can call global f’ns from within the class that act upon global arrays/vectors/deques of the classes.

i.e.

deque <Class1*> array1;
deque <Class2*> array2;

void testApp::fillArray1(){
array1.push_back(new Class1 () );
}

void testApp::fillArray2(){
array2.push_back(new Class2 () );
}

//

void Class1::dothisthing(){
testApp::instance->fillArray2();
}

//

void Class2::dothatthing(){
testApp::instance->fillArray1();
}

maybe that helps?

k

Thanks man -

That helped a ton. Basically what I did was made a class that managed all the arraylist. That object was then passed using ( & ) to all the other arraylist. Thanks again.

Todd