Problem implimenting .cpp file.

Discussion about everything. New games, 3d math, development tips...
Post Reply
MasterM
Posts: 128
Joined: Sat Oct 20, 2007 2:38 am
Location: netherlands antilles, Curacao

Problem implimenting .cpp file.

Post by MasterM »

Hey all, what i am trying to do is make a manager.h to declare the driver settings and options and a player.cpp to add a Iscenenode...
but for some reason i get errors like :


Main.cpp

Code: Select all

#include "manager.h"

int main(int argc, char** argv)
{

    while(device->run())
    {
        driver->beginScene(true, true, SColor(0,200,200,200));

        smgr->drawAll();
        guienv->drawAll();

        driver->endScene();
    }

    device->drop();

    return 0;
}
Manager.h

Code: Select all

#ifndef MAN_H
#define MAN_H

#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

 IrrlichtDevice *device =
        createDevice(EDT_OPENGL, dimension2d<s32>(640, 480), 32,
            false, false, false, 0);

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();

#endif
player.cpp

Code: Select all

#include "manager.h"

ISceneNode* mar=smgr->addSphereSceneNode();
but i get erros like :
obj\Debug\src\main.o||In function `_ZN3irr4core12irrAllocatorIcE12internal_newEj':|
obj\Debug\src\sars.o:C:\Work\Engines\irrlicht-1.4.2\include\irrAllocator.h|29|first defined here|
obj\Debug\src\main.o||In function `_ZN3irr4core12irrAllocatorIcE12internal_newEj':|
obj\Debug\src\sars.o:C:\Work\Engines\irrlicht-1.4.2\include\irrAllocator.h|29|first defined here|
obj\Debug\src\main.o||In function `_ZN3irr4core12irrAllocatorIcE12internal_newEj':|
obj\Debug\src\sars.o:C:\Work\Engines\irrlicht-1.4.2\include\irrAllocator.h|29|first defined here|
obj\Debug\src\main.o||In function `_ZN3irr4core12irrAllocatorIcE12internal_newEj':|
obj\Debug\src\sars.o:C:\Work\Engines\irrlicht-1.4.2\include\irrAllocator.h|29|first defined here|
||=== Build finished: 4 errors, 0 warnings ===|
and when i remove player.cpp everything runs fine...
Do you guys know what the problem is?Thanks.
C++ is not the Magdalena...it takes patience...shes like the well aged prostitute, it takes years to learn her tricks! she is cruel...laughs at you when you are naked...
Life of a programmer == Const abuse
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

ISceneNode* mar=smgr->addSphereSceneNode();
This line makes absolutely no sense outside of a function. You can only execute code within a function (and thus, have to call it from main() in some way).
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I would advise looking at some tutorials on classes and functions ;)
Image Image Image
MasterM
Posts: 128
Joined: Sat Oct 20, 2007 2:38 am
Location: netherlands antilles, Curacao

Post by MasterM »

I readed it but dont know where to use it correctly, can you give me a smal example on how to achieve what i am trying to do?
Thanks
C++ is not the Magdalena...it takes patience...shes like the well aged prostitute, it takes years to learn her tricks! she is cruel...laughs at you when you are naked...
Life of a programmer == Const abuse
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You should rethink your initialisation (starting from main() and adding function calls from there) and consider avoiding global variables completely.
twilight17
Posts: 362
Joined: Sun Dec 16, 2007 9:25 pm

Re: Problem implimenting .cpp file.

Post by twilight17 »

MasterM wrote:

Code: Select all

#include "manager.h"

ISceneNode* mar=smgr->addSphereSceneNode();
should be something like...

Code: Select all


#include "manager.h"

void CreatePlayerNode()
{
ISceneNode* mar = smgr->addSphereSceneNode();
}


*I just woke up, so cut me some slack if this is wrong.* :lol:
Post this userbar I made on other websites to show your support for Irrlicht!
Image
http://img147.imageshack.us/img147/1261 ... wernq4.png
psychophoniac
Posts: 101
Joined: Wed Dec 03, 2008 5:33 pm
Location: ger

Post by psychophoniac »

you should have a look on a C++ tutorial, dude.
i recommend this one: http://www.cplusplus.com/doc/tutorial/
good luck !
i love skateboarding!
MasterM
Posts: 128
Joined: Sat Oct 20, 2007 2:38 am
Location: netherlands antilles, Curacao

Post by MasterM »

Hmm thank you and i had a read on classes and functions but it still dont get everything...
How do i declare something like smgr to create objects in other class cause i tried everything but did not work or can anyone point me in the right direction of passing smgr from one class to another..thanks.
C++ is not the Magdalena...it takes patience...shes like the well aged prostitute, it takes years to learn her tricks! she is cruel...laughs at you when you are naked...
Life of a programmer == Const abuse
twilight17
Posts: 362
Joined: Sun Dec 16, 2007 9:25 pm

Post by twilight17 »

I think you're looking for inheritance.
Post this userbar I made on other websites to show your support for Irrlicht!
Image
http://img147.imageshack.us/img147/1261 ... wernq4.png
Post Reply