C++命名空间

样例:

#include <iostream>
using namespace std;
namespace Jack {
    int age;
    void sayHello() {
        cout << "hello, I'm Jack" << endl;
    }
}
namespace Johns {
    int age = 20;
    void sayHello() {
        cout << "hello, I'm Johns" << endl;
    }
}
int main() {
    Jack::age = 10;
    cout << Jack::age << endl;
    Jack::sayHello();
    cout << Johns::age << endl;
    using Johns::sayHello;
    sayHello();
    return 0;
}

 

posted @ 2016-07-08 19:39  月光诗人  阅读(147)  评论(0编辑  收藏  举报