• Advertisement
Sign in to follow this  

Using base applications members in a friend class

This topic is 4175 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using the OGRE app wizard for VC2005. I'm trying to use some members from my main app class but I'm having some problems... first I'm putting
class HOApp : public BaseApplication
{
public:
	HOApp(void);
	virtual ~HOApp(void);

	friend class Terrain;

protected:
	virtual void createScene(void);
};

and heres my Terrain class
#ifndef __Terrain_h_
#define __Terrain_h_

#include "HO.h"

class HOApp;

class Terrain
{

public:

	//Public methods
	Terrain(String aEntityName, String aMesh, String aMaterial);
	~Terrain();

protected:
	//Protected members
	Entity* mpEntity;
	String mEntityName;
	String mMesh;
	String mMaterial;

};

#endif

Then I'm trying to use the main apps member in the constructor.
Terrain::Terrain(String aEntityName, String aMesh, String aMaterial)
{

	mEntityName = aEntityName;
	mMesh = aMesh;
	mMaterial = aMaterial;

	mpEntity = HOApp::mSceneMgr->createEntity("Terrain" + mEntityName, mMesh);
}

but I get the error
error C2227: left of '->createEntity' must point to class/struct/union/generic type

Anyone know what I'm doing wrong? I'm kinda new to C++ but can code pretty good in C.

Share this post


Link to post
Share on other sites
Advertisement
the problem is HOApp::mSceneMgr isn't a pointer type or at least wherever you're calling this from doesn't know about HOApp::mSceneMgr. You can't dereference non-pointers with the arrow operator. So, since mSceneMgr isn't defined in HOApp, I'm assuming it's in BaseApplication. If we could see that code we may be able to help you more

Share this post


Link to post
Share on other sites
Here's the base application class in the base application header. The base application header is included in HO.h


class BaseApplication : public Ogre::Singleton<BaseApplication>, public FrameListener, public KeyListener
{
public:
BaseApplication(void);
virtual ~BaseApplication(void);

virtual void go(void);

protected:
virtual bool setup();
virtual bool configure(void);
virtual void chooseSceneManager(void);
virtual void createCamera(void);
virtual void createFrameListener(void);
virtual void createScene(void) = 0; // Override me!
virtual void destroyScene(void);
virtual void createViewports(void);
virtual void setupResources(void);
virtual void createResourceListener(void);
virtual void loadResources(void);
virtual void updateStats(void);
virtual bool processUnbufferedKeyInput(const FrameEvent& evt);
virtual bool processUnbufferedMouseInput(const FrameEvent& evt);
virtual void moveCamera();
virtual bool frameStarted(const FrameEvent& evt);
virtual bool frameEnded(const FrameEvent& evt);

void showDebugOverlay(bool show);
void switchMouseMode();
void switchKeyMode();
void keyClicked(KeyEvent* e);
void keyPressed(KeyEvent* e);
void keyReleased(KeyEvent* e);

Root *mRoot;
Camera* mCamera;
SceneManager* mSceneMgr;
RenderWindow* mWindow;
int mSceneDetailIndex ;
Real mMoveSpeed;
Degree mRotateSpeed;
Overlay* mDebugOverlay;
EventProcessor* mEventProcessor;
InputReader* mInputDevice;
Vector3 mTranslateVector;
bool mStatsOn;
bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
unsigned int mNumScreenShots;
float mMoveScale;
Degree mRotScale;
Real mTimeUntilNextToggle; // just to stop toggles flipping too fast
Radian mRotX, mRotY;
TextureFilterOptions mFiltering;
int mAniso;
};


Share this post


Link to post
Share on other sites
I changed my terrain constructor to include a scenemanager pointer as an argument. I think it should work.



Terrain::Terrain(SceneManager* ScnManRef, String aEntityName, String aMesh, String aMaterial)
{

mEntityName = aEntityName;
mMesh = aMesh;
mMaterial = aMaterial;

mpEntity = ScnManRef->createEntity("Terrain" + mEntityName, mMesh);
}


Share this post


Link to post
Share on other sites
The friend keyword do not take inheritance into account. If a class F is friend of a class A, it can't use the protected members of the ancestors of A. Also, classes that inherit F are not friends of A.

Regards,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement