Using base applications members in a friend class

Started by
3 comments, last by Emmanuel Deloget 17 years, 7 months ago
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.
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
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
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;};
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
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);}
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
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,

This topic is closed to new replies.

Advertisement