Jump to content
  • Advertisement
Sign in to follow this  
Jarwulf

get class recognized

This topic is 2599 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

Hi, I want to use the class SMEEUIManager but I'm having trouble finding a place to put it to get it recognized when its used.

It is defined in the file UIManager.h

I've tried including UIManager SMEEUIManager
in both class DemoApp or class OgreFramework



class DemoApp
{

UIManager SMEEUIManager;//addition

};





class OgreFramework : public Ogre::Singleton<OgreFramework>, OIS::KeyListener, OIS::MouseListener
{
UIManager SMEEUIManager;//addition

};





The program begins working its way through DemoApp::startDemo().



//DemoApp.cpp

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

OgreFramework::getSingletonPtr()->m_pLog->logMessage("Demo initialized!");

m_pAppStateManager = new AppStateManager();

MenuState::create(m_pAppStateManager, "MenuState");
GameStateII::create(m_pAppStateManager, "GameStateII");

m_pAppStateManager->start(m_pAppStateManager->findByName("MenuState"));


Note this line



OgreFramework::getSingletonPtr()->initOgre("AdvancedOgreFramework", 0, 0);


At this line in the function the program goes into AdvancedOgreFramework.cpp and the OgreFramework class where SMEEUIManager is called.

I got an error at here about SMEEUIManager being undeclared. so I moved the declaration to class OgreFramework. That seemed to take care of that error but the program control reverts back to startDemo and continues on to...



m_pAppStateManager->start(m_pAppStateManager->findByName("MenuState"));


which goes to


//AppStateManager.cpp

void AppStateManager::start(AppState* state)
{
changeAppState(state);


}


then


//AppStateManager.cpp

void AppStateManager::changeAppState(AppState* state)
{
m_ActiveStateStack.back()->enter();
}


and finally


//MenuState.cpp

void MenuState::enter()
{

SMEEUIManager.MenuReg();

}


Where I again get the error that SMEEUIManager is undeclared. How do I get SMEEUIManager recognized in both instances? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Your situation sounds a little involved, but I can say for sure that this will definitely not work:

void MenuState::enter()
{
SMEEUIManager.MenuReg();
}

you said that you have declared SMEEUIManager in the classes "DemoApp" and also in "OgreFramework", but not in "MenuState".

I have a suggestion though:
I am unfamiliar with Ogre, or the specific use of the UIManager object, but If you need that object to be shared between all your other classes, the following could be one solution:

in a file called "UIThingy.h"

#ifndef INC_UITHINGY_H
#define INC_UITHINGY_H

#include <UIManager.h>

// tell the compiler that myUIManager can be found somewhere in one of the object modules
extern UIManager SMEEUIManager;

#endif /* INC_UITHINGY_H */


inside "UIThingy.cpp"

#include "UIThingy.h"
// actually contruct the object here in the CPP file.
// This object will be constructed once when your
// program starts, and live until your game is closed.
UIManager SMEEUIManager;


now, simply include "UIThingy.h" in any file that needs access to the SMEEUIManager Object.

if the UIManager class is a resource hog, or you need to control the way that it is initialized, you can wrap a UIManager in your own class that creates and destroys a UIManager object as needed, and have that wrapper class declared in UIThingy.cpp instead.

Share this post


Link to post
Share on other sites
[font=arial, verdana, tahoma, sans-serif][size=2]This:[/font]UIManager SMEEUIManager;declares an instance of UIManager called SMEEUIManager. You said you wanted to use the class SMEEUIManager? You would have to do:SMEEUIManager someVariableName;Or maybe rather something like:SMEEUIManager* someVariableName = new SMEEUIManager( /* insert necessary arguments here */ );(although for it to be accessible, it should probably be declared outside the scope where it's allocated with new)Also, you mention stepping through code, but you're getting compile errors, meaning the program never actually gets compiled... How are you able to run anything?

Share this post


Link to post
Share on other sites
I'm still having trouble getting UIManager SMEEUIManager to work. Here is the flow of the program


main->Demoapp demo->demo.startDemo();

startDemo()->creation of an OgreFramework AND creation of a MenuState AND SMEEUIManager.UILoader(); AND entering into MenuState

MenuState->SMEEUIManager.UIMenuReg();


I'm trying various things but they won't work. I tried

1. Moving SMEEUIManager declaration to DemoApp class and it won't get recognized in Menustate. If you try to include DemoApp.h in Menustate.h you get errors since Menustate.h is already included in DemoApp.h

2. Putting extern UIManager SMEEUIManager in main() and it won't get recognized in Menustate

3. Moving SMEEUIManager to OgreFramework class doesn't work because OgreFramework.h is included in UIManager.h.

Share this post


Link to post
Share on other sites

2. Putting extern UIManager SMEEUIManager in main() and it won't get recognized in Menustate


That is not what I told you to do..

create two new files and follow my instructions, and it will work.

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!