Jump to content
  • Advertisement
Sign in to follow this  
Jarwulf

Class recognition

This topic is 2834 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 have a class called UIManager that I want to use but I'm having trouble getting it recognized in the subcomponents of the program. The error says its not declared.

The file with the class is included in Demo.hpp



#include "MenuState.hpp"
#include "GameStateII.h"
#include "UIManager.h"

//|||||||||||||||||||||||||||||||||||||||||||||||

class DemoApp
{
public:
DemoApp();
~DemoApp();

void startDemo();
UIManager SMEEUIManager;//addition
private:
AppStateManager* m_pAppStateManager;
bool m_bShutdown;
};




Once the program is started startDemo() gets into the OgreFramework class

void DemoApp::startDemo()
{
new OgreFramework();
OgreFramework::getSingletonPtr()->initOgre("AdvancedOgreFramework", 0, 0);



Once in the OgreFramework class I try to use it but I get a message that SMEEUIManager is not declared


void OgreFramework::initOgre(Ogre::String wndTitle, OIS::KeyListener *pKeyListener, OIS::MouseListener *pMouseListener)
{
SMEEUIManager.UILoader();//addition

}


Maybe the problem is that OgreFramework is created on the fly?

Share this post


Link to post
Share on other sites
Advertisement
My C++ is rusty (and was never that great to begin with), but based on the code you posted:

Since SMEEUIManager is declared in the definition for DemoApp objects, wouldn't you have to call it via an instantiated object? DemoApp.SMEEUIManager.UILoader(), for example? Or you could pass a pointer to SMEEUIManager as an argument.

I could be wrong, but even if I am, I don't think that dynamically creating an object prohibits you from accessing variables.

Share this post


Link to post
Share on other sites
You declare an instance of UIManager inside the DemoApp-class with the name SMEEUIManager.

Then you are trying to access it from the OgreFramework-class which does not contain
any member variable with the name SMEEUIManager of the type UIManager.

Either move UIManager-variable to the OgreFramework-class or just manage
the loading of the ui (UILoader-method) after you call the initOgre-method.
Or, alternatively, pass a reference of the variable as a paremeter to the initOgre-method.

Share this post


Link to post
Share on other sites
Hidden

You declare an instance of UIManager inside the DemoApp-class with the name SMEEUIManager.

Then you are trying to access it from the OgreFramework-class which does not contain
any member variable with the name SMEEUIManager of the type UIManager.

Either move UIManager-variable to the OgreFramework-class or just manage
the loading of the ui (UILoader-method) after you call the initOgre-method.
Or, alternatively, pass a reference of the variable as a paremeter to the initOgre-method.


On top of all that, you are trying to access what is probably a null pointer, as it is a pointer to the UIManager, and not a UIManager itself. Also, because it is a pointer you should be using -> rather than .

Share this post


Link to post
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!