CodingNovice
Programmer
I have been using C++ lately rather than C. In C we have no namespaces so defining a global variable in one translation unit and declaring it as extern in another is fine. I know I can also do that in C++ but what I am trying to do instead is to have a namespace scoped variable extern'ed. Can it be done?
I tried this but it gave errors....
file1.h
namespace NS
{
class A {};
}
global.cpp
#include "file1.h"
namespace NS
{
A object;
}
file1.cpp
#include "file1.h"
extern NS::A NS:bject;
int main()
{
// use object
return 0;
}
Its pretty obvious what I am trying to achieve. How do I do this?
I tried this but it gave errors....
file1.h
namespace NS
{
class A {};
}
global.cpp
#include "file1.h"
namespace NS
{
A object;
}
file1.cpp
#include "file1.h"
extern NS::A NS:bject;
int main()
{
// use object
return 0;
}
Its pretty obvious what I am trying to achieve. How do I do this?