Original Post
[source lang="cpp"]class Game{
list < GameObjects * > m_gos;
void Update(float delta){
for(list::it goIt ..)
(*goIt)->Update(delta);
}
...
};[/source]
Pseudo code..
Id like to make the Class Game the sole responsible for the creation and deletion of the gameobjects.
I always do this with a template function:
[source lang="cpp"]template< class derivedGO>
derivedGO* Create(){
derivedGO *p = new derivedGO();
m_gos.add(p);
return p;
}[/source]
And this is the only way to give the Game class the objects (so if they got created externally, they will not be part of the game).
The only (really annoying imo) problem is that derivedGO must provide a compatible constructor, this sucks, cause I always, then, have to create a Init(params) function that is always called just after calling create..
Is this poor design?
list < GameObjects * > m_gos;
void Update(float delta){
for(list::it goIt ..)
(*goIt)->Update(delta);
}
...
};[/source]
Pseudo code..
Id like to make the Class Game the sole responsible for the creation and deletion of the gameobjects.
I always do this with a template function:
[source lang="cpp"]template< class derivedGO>
derivedGO* Create(){
derivedGO *p = new derivedGO();
m_gos.add(p);
return p;
}[/source]
And this is the only way to give the Game class the objects (so if they got created externally, they will not be part of the game).
The only (really annoying imo) problem is that derivedGO must provide a compatible constructor, this sucks, cause I always, then, have to create a Init(params) function that is always called just after calling create..
Is this poor design?
