C++之Namespace使用源代码
// myspace.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;namespace A{string str = "hello, andylin!";void fun1(int nVal){cout << nVal << endl;}void fun2(string str){cout << str.c_str() << endl;}}namespace B{string str = "hello, baby!";void fun1(int nVal){cout << -nVal << endl;}void fun2(string str){ string strTemp(str.rbegin(), str.rend());cout << strTemp.c_str() << endl;}}int _tmain(int argc, _TCHAR* argv[]){A::fun1(123);B::fun1(123);A::fun2(B::str);B::fun2(A::str);return 0;}
页:
[1]