Sign in to follow this  
BreathOfLife

namespace shinanigans

Recommended Posts

header
namespace meo {
      int random(int low, int high);
} 

cpp
namespace meo {
      int random(int low, int high) {
      return ( ( rand() % (high - low + 1) ) + low ); 
}

}

then simply a call to meo::random(5,10); is generating unresolved externals. vc2008, recently just added a folder of my own to the include list, but that has been working fine, just this namespace bit is borking it up. [Edited by - BreathOfLife on September 14, 2008 8:44:41 PM]

Share this post


Link to post
Share on other sites
unfortunately thats just in the post

the namespace was added to an existing header that worked just fine before, and I cant seem to get this namespace thingy working

EDIT < more info > so this header/cpp file are in a folder that ive added to the paths and directories panal in the options menu

then I just #include <random.h> and thats it. maybe im skipping something or leaving something out. do they still need to be manually added to the project?

Share this post


Link to post
Share on other sites
Quote:
Original post by BreathOfLife
unfortunately thats just in the post

the namespace was added to an existing header that worked just fine before, and I cant seem to get this namespace thingy working

EDIT < more info > so this header/cpp file are in a folder that ive added to the paths and directories panal in the options menu

then I just #include <random.h> and thats it. maybe im skipping something or leaving something out. do they still need to be manually added to the project?



If I'm understanding this correctly, you are wanting to use meo::random in multiple projects. I am inferring that you are building common utility code from all your projects.

The main problem is the headers are not providing the definitions to your functions. There are a couple of solutions... :

1) Include the definitions (random.cpp) in one of your project's .cpp to provide its definitions in random.h. This will generate the .cpp in question symbols and random.cpp symbols and combine them together into the .obj file used by the linker. Although... I'm not sure how this fairs in the "good programming practices" category.

2) Produce a static-link library and link your project to it. This will provide random.cpp's symbols in the library. However, it requires you to build the library and rebuild it each time you change it.


Hope this helps!

Share this post


Link to post
Share on other sites
The compiller will parse all .cpp in the solution browser, so you should had at least all the cpp files. The .h file get parsed when included from a .cpp file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this