So here is my problem, I want a vector of objects of a certain class that I can then pass to other classes for use.
I want the Vector to add an instance of the class within the constructor of that class. So I've set up a static vector inside the class members and in the constructor I want to try and push_back(this) if that makes any sense.
There are 2 classes currently at work, one is the event handler class that creates an instance of "Obstacle" class (the class I want a vector of) every time there is a left click.
(I have omitted irrelevant bits of code)
class MyEventReceiver: public IEventReceiver
{
private:
blah blah
public:
blah blah
virtual bool OnEvent (const SEvent& event){
if(left click)
Obstacle obs(scn,randX,randY,randR);
}
}
Obstacle.h:
class Obstacle
{
private:
static std::vector<Obstacle> *obs;
public:
Obstacle(scene::ISceneManager*, float, float, float);
~Obstacle();
};
Obstacle cpp:
std::vector<Obstacle> *Obstacle::obs;
Obstacle::Obstacle(scene::ISceneManager* scn, float x, float y, float radius)
{
//get and set the passed in params blah blah
obs->push_back(this);
}
This doesn't work, but hopefully you can see what I'm trying to achieve. Later on I want a function that will return a reference to obs so other classes can call this function and gain access to the vector to manipulate and read it.