C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

namespace problem

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
vsgdp
Guest





PostPosted: Sun Sep 28, 2003 4:31 am    Post subject: namespace problem Reply with 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?



Back to top
Gianni Mariani
Guest





PostPosted: Sun Sep 28, 2003 6:39 am    Post subject: Re: namespace problem Reply with quote



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





PostPosted: Sun Sep 28, 2003 7:32 am    Post subject: Re: namespace problem Reply with quote



Most excellant. Thanks!


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.