0

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

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by sblass92
1

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
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.