Greetings All,
I have one class I'll call Main class and it creates and initializes all of the classes so that they are not re-created again. What I simply want to do is to have in the constructors of my other classes pointers to the classes they need to operate.
I get errors when I try, and I have looked in various forums. The question is, how is the proper way to do this, if it can/should be done. I don't want to have to pass each one for each function that needs it. Thank you in advance for any help.
here is the class *constructor* that creates the new classes Main
1 2 3 4 5 6 7 8
|
EcoAreaTeam* m_pEcoAreaTeam = new EcoAreaTeam();
LifePattern* m_pLifePattern = new LifePattern();
NeedTeam* m_pNeedTeam = new NeedTeam();
SceneFrameTeam* m_pSceneFrameTeam = new SceneFrameTeam(m_pEcoAreaTeam, m_pStatisticCalculation,
m_pSymptomManager, m_pTrioTeam);
StatisticCalculation* m_pStatisticCalculation = new StatisticCalculation();
SymptomManager* m_pSymptomManager = new SymptomManager();
TrioTeam* m_pTrioTeam = new TrioTeam();
|
here is a class that i trying to use to access pointers to other classes in the .cpp file
1 2 3 4 5 6 7 8
|
SceneFrameTeam::SceneFrameTeam(EcoAreaTeam* eco, StatisticCalculation* stat,
SymptomManager* sym, TrioTeam* trio):
m_pEcoAreaTeam(eco),
m_pStatisticCalculation(stat),
m_pSymptomManager(sym),
m_pTrioTeam(trio){}
|
here is the .h file creation information for SceneFrameTeam:
1 2 3 4 5 6 7 8 9 10 11 12
|
class EcoAreaTeam;
class SceneFrameBase;
class StatisticCalculation;
class SymptomManager;
class TrioTeam;
//these are the pointers to the classes in the SceneFrameTeam .h
EcoAreaTeam* m_pEcoAreaTeam;
StatisticCalculation* m_pStatisticCalculation;
SymptomManager* m_pSymptomManager;
TrioTeam* m_pTrioTeam;
|
here is the constructor info in .h:
[CODE]
SceneFrameTeam(EcoAreaTeam* eco,
StatisticCalculation* stat,
SymptomManager* sym,
TrioTeam* trio);
[/code]
this is the error message:
error C2065: 'eco' : undeclared identifier
|
and
error C3867: 'SceneFrameTeam::EcoAreaTeam': function call missing argument list; use '&SceneFrameTeam::EcoAreaTeam' to create a pointer to member
|
the thing is I was looking at an example from Matt Buckland's AI book and he did not seem to need the &
I guess the question is, is there a simple way to do this?
Peace,
Marcia