inheritance and parent problem

hi

my app structure is currently looking like this:

testApp

  • appCV
  • sceneManager
    – baseScene

So in testApp I’ve a class called appCv and a sceneManager class.

I then have a baseScene class, then various scenes, lets say sceneSnow, sceneSun that extend baseScene

  
  
class sceneSnow: public baseScene{  
  

in sceneManager.h I have:

  
  
// at top  
#include "sceneSnow.h"  
#include "sceneSun.h"  
  
// in public  
baseScene **    scenes;  
  
  

in sceneManager.cpp setup i have:

  
  
scenes = new baseScene*[2];  
  
scenes[0]               = new sceneSnow();  
scenes[1]               = new sceneSun();  
  
for(int i=0; i<2; i++){  
	scenes[i]->init();  
}  
  

  1. For those in the know is this the best way to go about it?

Yes I could just have:
sceneSnow snow;
sceneSun sun;

but that becomes more problematic later on, and prefer them in an array so I can do
scenes[currentScene]->draw()

  1. From within my scene, I need to be able to call return functions in appCv.

For simplicity, am I better off in testApp update just passing values into sceneManager to copy them into each scene?

Anyway, at the top of baseScene.h I’ve got

  
  
// at top  
class sceneManager;  
  
// in public  
void setParent(sceneManager * p){ parent = p;}  
  
sceneManager * parent;  
  

And at the top of baseScene.cpp I’ve got #include “sceneManager.h”

However this isn’t working. Is it the way I am using the pointers to classes? The compiler is telling me in baseScene.cpp it can’t find sceneManager.h, although I know this way of communicating with the parent should work.

Any ideas would be greatly appreciated.

Thanks

And at the top of baseScene.cpp I’ve got #include “sceneManager.h”

However this isn’t working. Is it the way I am using the pointers to classes? The compiler is telling me in baseScene.cpp it can’t find sceneManager.h, although I know this way of communicating with the parent should work.

if it’s complaining about the file it’s surely because it can’t actually find it, perhaps search paths, do you have them in folders? or a typo in the include?

everything else seems ok, i would use a vector of baseScene* instead of the more confusing ** but the structure seems ok.

hey arturo

In sceneManager.h I now have

vector <baseScene*> scenes;

and in .cpp setup I have

scenes.push_back( sceneSun() );
scenes.push_back( sceneSnow() );

This seemed to build now. The sceneManager.h was in the src folder, I added src folder to the search path just to be sure.

but now in sceneSnow (that extends baseScene which has the reference to sceneManager in) I am getting here:

  
  
sceneSnow::update(){  
  
parent->getValue(0, 0, 10, 10);  
  
}  
  

Error:
error: invalid use of incomplete type 'struct sceneManager’

Do you think its because I have my reference to sceneManager in baseScene? Should I just put it within each class, ie snowScene & sunScene rather than in baseScene? I thought this should work really.

Cheers

that seems related to recursive includes, make sure that you’re only including from one of the .h th other one, doing the forward declaration in the other and including the .h in the .cpp

sceneSnow.h:

  
#include "sceneManager.h"  

sceneManager.h

  
class sceneSnow;  

sceneManager.cpp

  
#include "sceneSnow.h"  

or the oppposite. this is only going to work if the file in which you are doing the forward declaration only has pointers or references to the forward declared class.