Code: Select all
#ifndef STAGEOBJECT_H
#define STAGEOBJECT_H
#include <GL/gl.h>
class stageObject
{
public:
GLfloat x, y;
//sprites
stageObject();
virtual void update()=0;
virtual void draw()=0;
private:
// add your private declarations
};
#endif // STAGEOBJECT_H
Code: Select all
#ifndef HECTOR_H
#define HECTOR_H
#include "stageobject.h"
class hector: public stageObject
{
public:
int test;
hector();
virtual ~hector();
void update();
void draw();
private:
// add your private declarations
};
#endif // HECTOR_H
Code: Select all
#ifndef STAGE_H
#define STAGE_H
#include <list>
#include "stageobject.h"
class stage
{
public:
std::list<stageObject*> stageObjects;
std::list<stageObject*>::iterator i;
stage();
private:
// add your private declarations
};
#endif // STAGE_H
Code: Select all
#include "stage.h"
#include "hector.h"
stage::stage()
{
hector *dude = new hector;
stageObjects.push_back(dude);
}
Now, in my main I make a new stage and try to iterate through the list and assign a value to one of the stageObject's member variables...
Code: Select all
stage *gameStage = new stage;
//try to interate thru that list that stage has
for(gameStage->i=gameStage->stageObjects.begin(); gameStage->i != gameStage->stageObjects.end(); ++gameStage->i)
{
gameStage->i->x = 44;
}
Code: Select all
main.cpp:196: error: request for member ‘x’ in ‘* gameStage->stage::i.std::_List_iterator<_Tp>::operator-> [with _Tp = stageObject*]()’, which is of non-class type ‘stageObject*’