怎样定义命名空间

命名空间关键字:namespace 

namespace A                                     

{                                                    

    int x = 0;

    void f1();

    void f2();

}

namespace B

{

   int x = 2;

    void f1();

    void f3();   

}

cout << A::x<<endl;

 B::f1();

 

#include<stdlib.h>
#include<iostream>
//using namespace std;

namespace A
{
int x = 1;
void fun()
{
std::cout << "A" << std::endl;
}
}

namespace B
{
int x = 2;
void fun()
{
std::cout << "B" << std::endl;
}
void fun2()
{
std::cout << "BB" << std::endl;
}
}
using namespace B;
int main()
{
std::cout << A::x<<std::endl;
B::fun();
fun2();
std::cout << "hello" <<std:: endl;
system("pause");
return 0;
}

posted @ 2016-09-10 14:41  sarah_lxq  阅读(278)  评论(0)    收藏  举报