 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
vsgdp Guest
|
Posted: Sun Sep 28, 2003 4:31 am Post subject: namespace problem |
|
|
I have a few variables that need to be global, but they are related and I
thought it be cleaner to put them in a namespace:
namespace x
{
A* a;
B b;
C c;
}
Several modules need access to this namespace, but I am getting a linker
error
"already defined in whatever.obj"
This is similar to what happens if I used plain globals, but that is easily
fixed by using extern and initializing the globals in one implementation
file. I tried to do something similar here but it didn't work. Any
solutions?
|
|
| Back to top |
|
 |
Gianni Mariani Guest
|
Posted: Sun Sep 28, 2003 6:39 am Post subject: Re: namespace problem |
|
|
vsgdp wrote:
| Quote: | I have a few variables that need to be global, but they are related and I
thought it be cleaner to put them in a namespace:
namespace x
{
A* a;
B b;
C c;
}
Several modules need access to this namespace, but I am getting a linker
error
"already defined in whatever.obj"
This is similar to what happens if I used plain globals, but that is easily
fixed by using extern and initializing the globals in one implementation
file. I tried to do something similar here but it didn't work. Any
solutions?
|
Try again - this below should work.
------- header file --------
namespace xxx
{
extern int a;
extern char foo[];
};
----------------------------
------- implementation cpp file -------
#include "header-file"
namespace xxx
{
int a = 2;
char foo[] = "ABCD";
};
---------------------------------------
|
|
| Back to top |
|
 |
vsgdp Guest
|
Posted: Sun Sep 28, 2003 7:32 am Post subject: Re: namespace problem |
|
|
Most excellant. Thanks!
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|