Page 1 of 1

Basic Question about OOP

Posted: Wed Mar 29, 2006 12:21 pm
by Das Gurke
I want to make a little GUI for my game and made so far no use of Object Orientation. I guess I understood the basics but now I am at a sort of dead point.

I divided my source into multiple Files and don't quite get the hang on how to do this with the IrrEventReceiver Class. My Code:

[CPP]

Code: Select all

#include "Irrlicht_Defs.h"
#include "IrrLoadScreen.h"
#include "Bomberman_Defs.h"
#include "Bomberman.h"
#include "INI.h"
#include "Graphics.h"
#include "IrrExtern.h"
#include "IrrEventReceiver.h"

//##############################################################################

class IrrEventReceiver
{
public:
	virtual bool OnEvent(irr::SEvent event)
	{
		if (event.EventType == irr::EET_GUI_EVENT)
		{
			irr::s32 id = event.GUIEvent.Caller->getID();
			irr::gui::IGUIEnvironment* env = IrrDevice->getGUIEnvironment();

            switch(event.GUIEvent.EventType)
            {
			case irr::gui::EGET_BUTTON_CLICKED:
              if (id == 101)
              {

              }
          }
       }
    }
 };
[H]

Code: Select all

#ifndef IRREVENTRECEIVER_H
#define IRREVENTRECEIVER_H

class IrrEventReceiver : public irr::IEventReceiver
{
	public:
		virtual bool OnEvent(irr::SEvent event);
};

#endif IRREVENTRECEIVER_H
Error is:
Class Type redefinition, so I just left the class out in the CPP, leads to different errors.

Hope somebody understands me to point to the correct direction.

Posted: Wed Mar 29, 2006 12:40 pm
by sudi
Ok learn c++

.cxx

Code: Select all

 #include "Irrlicht_Defs.h"
#include "IrrLoadScreen.h"
#include "Bomberman_Defs.h"
#include "Bomberman.h"
#include "INI.h"
#include "Graphics.h"
#include "IrrExtern.h"
#include "IrrEventReceiver.h"

//##############################################################################
   virtual bool IrrEventReceiver::OnEvent(irr::SEvent event)
   {
      if (event.EventType == irr::EET_GUI_EVENT)
      {
         irr::s32 id = event.GUIEvent.Caller->getID();
         irr::gui::IGUIEnvironment* env = IrrDevice->getGUIEnvironment();

            switch(event.GUIEvent.EventType)
            {
         case irr::gui::EGET_BUTTON_CLICKED:
              if (id == 101)
              {

              }
          }
       }
    }
.h

Code: Select all

the header was right

Posted: Wed Mar 29, 2006 12:49 pm
by Das Gurke
Mhm, not quite :(

Code: Select all

.\bomberman\IrrEventReceiver.cpp(13) : error C2723: 'IrrEventReceiver::OnEvent' : 'virtual' storage-class specifier illegal on function definition
Guess I really should start off with OOP :roll:

Posted: Wed Mar 29, 2006 1:14 pm
by hybrid
Or just do what the compiler tells you and test again. So remove the virtual in front of the method and it should work. But yes, without knowledge of C++ you're damn lost here.

Posted: Wed Mar 29, 2006 2:55 pm
by sudi
sry forgot to remove the virtual..... :oops: while telling u to learn c++