namespace 예제입니다.
#include<iostream>
using namespace std;
namespace firstNS
{
class demo{
int i;
public:
demo(int _i){
i = _i;
};
~demo(){};
int geti(){
return i;
}
void seti(int _i){
i = _i;
}
};
char str[]="illustracting namespace\n";
int counter;
}
namespace secondNS
{
int x, y;
}
int main(){
//using namesapce firstNS;
firstNS::demo ob(10);
cout << "value of ob is : " << ob.geti() << endl;
ob.seti(99);
cout << "value of ob is : " << ob.geti() << endl;
//using firstNS::str;
cout << firstNS::str;
using namespace firstNS;
for(counter = 10; counter; counter--)
cout << counter << endl;
secondNS::x = 10;
secondNS::y = 20;
cout << "x, y: " << secondNS::x << "," << secondNS::y << endl;
using namespace secondNS;
demo xob(x), yob(y);
cout << "xob, yob:" << xob.geti() << "," << yob.geti() << endl;
return 0;
}