Jump to content
  • Advertisement
Sign in to follow this  
Waterlimon

Unres. ext. symbol with function decl. in header and definition in cpp

This topic is 2628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a header file like


//A.h
namespace header
{
void func();
}


another header like


//B.h
namespace headers
{
#include "A.h"
}


and a cpp like


//C.cpp
#include "A.h"
void header::func()
{
DoStuff();
}


and the main cpp


//main.cpp
#include "B.h"
int TheFancyWindowsMainFunction()
{
headers::header::func();
}



My problem is that for some reason i get the "Unresolved external symbol blah blah referenced in function TheFancyWindowsandsoon" error.

Is there something wrong with the way ive set up the headers and all?

Both of the headers have inclusion guards.

Ill post the code if you cant see anything wrong with that... I tried throwing around some keywords and changing the places of stuff, but the function is only found if i define it in the header.

Oh and the cpp's are in the Source files directory and the headers in the Header files one. (MSVC++ 2010 express)

Share this post


Link to post
Share on other sites
Advertisement
You've declared the function headers::header::func(), but defined the function as header::func(). So when the linker goes looking for headers::header::func(), it doesn't find it. Avoid #including file inside of namespaces, the resulting aliasing mess is rarely worth it.

Share this post


Link to post
Share on other sites
You shouldn't include a header file within a namespace block: It will confuse the hell out of everybody, including yourself. Why were you trying to do that?

Share this post


Link to post
Share on other sites

You shouldn't include a header file within a namespace block: It will confuse the hell out of everybody, including yourself. Why were you trying to do that?


I wanted the stuff in the header inside a namespace with a bunch of other headers... Gotta figure out a cleaner way to do it...

Share this post


Link to post
Share on other sites
Another question:
How exactly do i declare an array in a header without making it complain about multiple versions found OR unresolved external symbol?
I tried making it static and const and extern and stuff but cant figure it out...
Cannot put it in the class because the class is a template and it would make multiple copies.

Share this post


Link to post
Share on other sites
Global arrays work just like any other global variable. In the header you create an extern declaration. In one source file you place the definition.

extern Mahclass<1, 2> Array[1024]; // in a header file

Mahclass<1, 2> Array [1024]; // in one source file

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!