Noob C++ question..

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
Murloc992
Posts: 272
Joined: Mon Apr 13, 2009 2:45 pm
Location: Utena,Lithuania

Noob C++ question..

Post by Murloc992 »

Sup, I have very stupid problem and I hope it's easier to solve it than I think.

Let's say I have a header full of random usefull functions, like code snippets header with a namespace.

Code: Select all

#ifndef SNIPS_H
#define SNIPS_H

include "Irrlicht.h"

namespace snips
{

void function_one(...)
{
...
}

irr::f32 function_two(...)
{
...
}

//and so on

}

#endif
Looks ok, but I am having really bad problems. I can't use it in any different .cpp files because I get already defined in obj *insert object name here*.obj error and actually don't know what to do now.. I have tried making header/cpp structure for the functions, only defines inside the header and declarations inside cpp, no luck.

Can somebody help me with this?

Thanks in advance!
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Noob C++ question..

Post by Acki »

Murloc992 wrote:I have tried making header/cpp structure for the functions, only defines inside the header and declarations inside cpp, no luck.
hmm, this should work... :shock:

you can also try making the functions static:

Code: Select all

#ifndef SNIPS_H
#define SNIPS_H

include "Irrlicht.h"

namespace snips
{

static void function_one(...)
{
...
}

static irr::f32 function_two(...)
{
...
}

//and so on

}

#endif
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Murloc992
Posts: 272
Joined: Mon Apr 13, 2009 2:45 pm
Location: Utena,Lithuania

Re: Noob C++ question..

Post by Murloc992 »

Acki wrote:
Murloc992 wrote:I have tried making header/cpp structure for the functions, only defines inside the header and declarations inside cpp, no luck.
hmm, this should work... :shock:

you can also try making the functions static:

Code: Select all

#ifndef SNIPS_H
#define SNIPS_H

include "Irrlicht.h"

namespace snips
{

static void function_one(...)
{
...
}

static irr::f32 function_two(...)
{
...
}

//and so on

}

#endif
Yeah, static worked :) Thanks!
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

lol
Header.h:

Code: Select all

#ifndef SNIPS_H
#define SNIPS_H

include "Irrlicht.h"

namespace snips
{

void function_one(...);

irr::f32 function_two(...);

//and so on

}

#endif
Header.cpp

Code: Select all

include "Header.h"

namespace snips
{

void function_one(...)
{
...
}

irr::f32 function_two(...)
{
...
}

}
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Murloc992
Posts: 272
Joined: Mon Apr 13, 2009 2:45 pm
Location: Utena,Lithuania

Post by Murloc992 »

Sudi wrote:lol
Header.h:

Code: Select all

#ifndef SNIPS_H
#define SNIPS_H

include "Irrlicht.h"

namespace snips
{

void function_one(...);

irr::f32 function_two(...);

//and so on

}

#endif
Header.cpp

Code: Select all

include "Header.h"

namespace snips
{

void function_one(...)
{
...
}

irr::f32 function_two(...)
{
...
}

}
I see you need to learn to read because I have stated that separate h/cpp doesn't work when used in separate cpp's while static does. :)
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

LOL! I actually laughed out loud :)
Kalango
Posts: 157
Joined: Thu Apr 26, 2007 12:46 am

Post by Kalango »

Murloc992 wrote: I see you need to learn to read because I have stated that separate h/cpp doesn't work when used in separate cpp's while static does. :)
Well, there is a keyword named 'extern', that would be like:

Code: Select all

//CPP

extern void foo1()
{
}
and in the .h you would write the function definition
...or is it the opposite?
...you shold try...

PS: Oh yes, and i think it would work if you put like:

Code: Select all

void snip::foo1()
{
}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, if you put the declaration (even an empty one like {} ) into the .h file it won't work. Moreover, exten is redundant if you just put a declaration into the .h file. There's no reason why a separate .h/.cpp file would not work, it's just a matter of proper declaration/definition.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

The way Sudi showed should work.
Declaration in the .h file
Definition in the .cpp file
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

"Whoops..."
Murloc992
Posts: 272
Joined: Mon Apr 13, 2009 2:45 pm
Location: Utena,Lithuania

Post by Murloc992 »

Ah, actually it was my mistake after all. When tried to do .h/.cpp I forgot to include namespace snips inside the cpp which lead to meant behaviour. So sorry and thanks Sudi.. :oops:
Post Reply