How to access members of the namespace in different files?
Amswer:
With help of an extern keyword, we can do this, see the below example code.
//common.h #ifndef COMMON_H_INCLUDED #define COMMON_H_INCLUDED namespace ATIC { extern int data; } #endif // COMMON_H_INCLUDED
//test.cpp #include "common.h" namespace ATIC { int data = 27; }
//main.cpp #include <iostream> #include "common.h" int main() { std::cout << ATIC::data << std::endl; return 0; }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Amswer:
With help of an extern keyword, we can do this, see the below example code.
need an explanation for this answer? contact us directly to get an explanation for this answer