member function without object

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
grunt
Posts: 96
Joined: Tue Aug 17, 2004 9:14 pm
Contact:

member function without object

Post by grunt »

I know basic c, but have dealt with any gui elements before. Mine was mostly dos prompt apps. I did the bsp rendering and collision detection tut, and all works well. I seem to be having a problem with Getting the menu to load however.

In my GameMain.cpp:

Code: Select all

int main()
{
    //run the menu
    MenuMain::RunMenu();

}
and then another function below it for the rendering and collision detection.

Then i have the MenuMain.cpp that holds the main GUI code:

Code: Select all

void MenuMain::RunMenu()
{
    //fullscreen variable
    bool fullscreen = true;
    
    //create the device - ogl and fullscreen
    device = createDevice(video::EDT_OPENGL,
             core::dimension2d<s32>(1024, 768), 32, fullscreen);
             
    //set the window caption
    device->setWindowCaption(L"Made Man");
    
    //set the driver and gui environment
    video::IVideoDriver* driver = device->getVideoDriver();
             IGUIEnvironment* env = device->getGUIEnvironment();
             
    gui::IGUIContextMenu* menu = device->getGUIEnvironment()->addContextMenu(r, 0, 45);
    
    //add the buttons
    menu->addButton(rect<s32>(10,170,100,240), 0, 101, L"New Game");
    menu->addButton(rect<s32>(10,190,100,290), 0, 102, L"Load Game");
    menu->addButton(rect<s32>(10,210,100,340), 0, 103, L"Save Game");
    menu->addButton(rect<s32>(10,230,100,390), 0, 104, L"Multiplayer");
    menu->addButton(rect<s32>(10,250,100,440), 0, 105, L"Options");
    menu->addButton(rect<s32>(10,270,100,490), 0, 106, L"Quit");
    
    //set the font
    IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp");
    
    //set the logo
    IGUIImage* logo = env->addImage(rect<int>(10,10,98,41));
    logo->setImage(driver->getTexture("../../media/mademan.jpg"));
    
    //set the background image
    IGUIImage* bground = env->addImage(rect<int>(10,10,98,41));
    bground->setImage(driver->getTexture("../../media/mademan_back.jpg"));
    
    //draw everything
    while(device->run() && driver)
          if (device->isWindowActive()) 
          {
                driver->beginScene(true, true, SColor(0,122,65,171));
                env->drawAll();
                driver->endScene();
          }

  device->drop();
}
I will get the button positions, and transparency correct, I just want to get hte menu to display 1st before I work on the little things.

Then I have the header file:

Code: Select all

/include the headers
#include <irrlicht.h>

//set up the namespace
using namespace irr;

class MenuMain : public IEventReceiver
{
public:

	//run menu function
    void RunMenu();

private:
	
	//fullscreen variable
	bool fullscreen;
};
Devc++ seems to be complaing that
30 C:\GameDemo\GameMain.cpp cannot call member function `void MenuMain::RunMenu()' without object
and i have include MenuMain.h in my main cpp file. Can somebody at least point me in the right direction at how to fix this?
2camjohn
Posts: 6
Joined: Wed Aug 04, 2004 1:15 pm

Post by 2camjohn »

I am no expert, but does this work ?

Code: Select all

 int main()
{
    //run the menu
    MenuMain.RunMenu();

}
Space Construction Game

Texturers, Story Writers and ideas people needed.
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

The above wouldn't work as MainMenu isn't defined anywhere, it has no clue what you are trying to do.

As for calling a class function using class::function(), this is incorrect. There are two ways of accessing a class.

1.

Class classObject

This way creates a direct link to the class, you don't have to worry about creating and destroying memory as this pointer is leading straight to the class.

2.

Class* classObject

This way creates a pointer to the class. To initilise the class, you will also need this line:

classObject = new Class

This creates a new area of memory, with the type being your class. You can have as many seperate pointers as you want, each instance of a new pointer means that the data is seperate from any other class.

Since you are only accessing the class once, you would be best off with a direct link. This is the code you need to get it to work.

Code: Select all

MenuMain menu;

menu.RunMenu();
If you wanted to use a pointer instead of a direct link, then you would use this code:

Code: Select all

MenuMain* menu = new MenuMain;
menu->RunMenu();
delete menu;
Guest

Post by Guest »

thank-you for the help, TYN. It is greatly appreciated.

That fixed almost all of the errors except one. It says:
[Linker error] undefined reference to `vtable for MenuMain'
and there is no line that it links to.

I swear im giving up....been working at this for hours. One after another. :cry:
Guest

Post by Guest »

Well,
it seems the linker has no clue
where you have defined the 'virtual' function table
for class* MenuMain (vtables are like POD's).
Where have u included the "header" file for it?

I guess now what it should like to be:

Main.cpp

Code: Select all


//include the headers 
#include <irrlicht.h> 

//set up the namespace 
using namespace irr;

#include "MenuMain.h" 

MenuMain.cpp

Code: Select all


#include "MenuMain.h" 

Post Reply