![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 1
Rep Power: 0
![]() |
C++ namespace question
Hi all,
I'm trying to use the "namespace" feature of C++ but I'm getting linker errors (I'm using Visual Studios). It seems like the fix should be trivial but I don't know how to do it. Here's what I'm doing: -------- Main File -------------------- #include (the standard stuff)
#include "inner_file.h"
#include "outer_file.h"
int main()
{
inner::f();
...
outer::f();
}namespace inner
{
int A[10];
void f();
}#include "inner_file.h"
namespace inner
{
void f() { /* implementation */ }
}Then I also have "outer_file.h" and "outer_file.cpp" but they're the same as the inner_files with the exception that the namespace is now "outer". When I compile it, I get a linker errorr saying that inner::A already defined in main_file.obj outer::A already defined in main_file.obj (or something along those lines) What am I doing wrong? Thanks, Kevin |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
The problem is that you're defining variables in .h files, which you're not supposed to do.
int A[10]; don't do that in a .h file. The problem has nothing to do with namespaces, which you are using correctly. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|