C++ namespace in multiple files

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p align=left><font face=Arial size=2>Is a namespace good for having global data available to several files that are part of the same project?  If so, then how do I code it so I dont get errors at link time saying that something has already been defined.</font>
<p align=left>What I used to do before I decided to try namespaces was to have an .h file with all of my global variables in it and then in all but one of my source files I would declare a pointer to the structure within the .h file to be extern.  I was hoping that namespaces would be easier and I fully expect them to be if I can ever figure out how to use them.
<p align=left> 
<p align=left>My plan was to have one .h file with the namespace in it and then include that .h file whenever I needed it and then say using namespace plotpoints;
<p align=left>Can this be done?
<p align=left>Thanks,
<p align=left>Ken

View the full article
 
Back
Top