主题:c++ Namespace的问题
			 iebboy
				 [专家分:0]  发布于 2011-04-04 09:47:00
 iebboy
				 [专家分:0]  发布于 2011-04-04 09:47:00							
			可不可以把不同文件中的对象放在同一个命名空间中。
#include<iostream>
#include<stack>
using namespace std;
iostream和stack是不同的文件,它们是怎么被放在std namespace 中的。
初学者~~~
						
					 
		
			
回复列表 (共2个回复)
		
								
				沙发
				
					 sarrow [专家分:35660]  发布于 2011-04-04 12:04:00
sarrow [专家分:35660]  发布于 2011-04-04 12:04:00				
				namespace 是跨文件的。
// file1.cpp
namespace my_lib {
    void Func1() {}
    class C1() {};
}
// file2.cpp
namespace my_lib {
    void Func2() {}
    class C2() {};
}
那么,函数Func1 和 Func2,以及类 C1,C2都在同一个 namespace,即my_lib里面。
"初学者" 的话,就找本新一点的教材来看,应该都有讲这些的。
							 
						
				板凳
				
					 475155927 [专家分:0]  发布于 2011-04-05 14:19:00
475155927 [专家分:0]  发布于 2011-04-05 14:19:00				
				#include<iostream>
#include<stack>
using namespace std;
可以用
#include<iostream.h>
#include<stack.h>
这样就可以省去using namespace std;
							 
									
			
我来回复