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.
Murloc992
Posts: 272 Joined: Mon Apr 13, 2009 2:45 pm
Location: Utena,Lithuania
Post
by Murloc992 » Fri Apr 30, 2010 6:51 pm
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:
Post
by Acki » Fri Apr 30, 2010 7:20 pm
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...
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
Murloc992
Posts: 272 Joined: Mon Apr 13, 2009 2:45 pm
Location: Utena,Lithuania
Post
by Murloc992 » Fri Apr 30, 2010 7:53 pm
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...
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 » Fri Apr 30, 2010 9:20 pm
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 » Fri Apr 30, 2010 9:40 pm
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 » Fri Apr 30, 2010 10:07 pm
LOL! I actually laughed out loud
Kalango
Posts: 157 Joined: Thu Apr 26, 2007 12:46 am
Post
by Kalango » Fri Apr 30, 2010 11:58 pm
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:
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:
hybrid
Admin
Posts: 14143 Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:
Post
by hybrid » Sat May 01, 2010 1:10 am
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 » Sat May 01, 2010 6:23 am
The way Sudi showed should work.
Declaration in the .h file
Definition in the .cpp file
I can hear birds chirping
I live in the Eye of Insanity.
Murloc992
Posts: 272 Joined: Mon Apr 13, 2009 2:45 pm
Location: Utena,Lithuania
Post
by Murloc992 » Sat May 01, 2010 8:27 am
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 ..