Hi,
I'm trying to create a vector array that contains pointers, and these pointers point to objects(particles) that have been created while the program is running.

How do I use the appropriate de-reference operator to use functions of the class particle?
ex. particle.move();
Here is what I have and my guess:

#include <vector>
#include <particle.h>

void main() {
vector <particle*> vect_a;

vect_a.push_back(new particle);

*(vect_a[0]).move();

}

Here, the compiler doesn't think i've declared 'move', but particle.move() works fine outside of the vector of pointers.

-Thanks

Try something like this :

#include <vector>
#include <particle.h>

using std::vector;

int main() {
vector <particle*> vec;
vec.push_back(new particle());
vec.front()->move(); //option 1
vec[0]->move(); //option 2
}

Solved the problem,

thanks much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.