在不同的C文件之间定义和使用namespace-{namespace的初级定义和使用(2)}

怎么用

例子:func3file2NameSpace2里面
把func3声明在TestNamespace.h里面
在file1里面使用的时候,需要using关键字声明NameSpace2

file1 (namespace_def_used.cpp)

#include <stdio.h>
#include "TestNamespace.h"

//define a name space
namespace NameSpace1
{
	void func2(void)
	{
		printf("this is function 2 in namespace !\n");
	}
	
}

void func1(void)
{
	printf("this is default function One!\n");
	
}

/* //method-2 usage of namespace  
using NameSpace1::func2;		//declare func2 which in NameSpace1 */

/* //method-3 usage of namespace  
using namespace NameSpace1;		//declare func2 which in NameSpace1	 */

using namespace NameSpace2;		//delcare NameSpace2

int main(void)
{
	func1();
/* 	//method-1 usage of namespace 
	NameSpace1::func2();  */	//declare func2 which in NameSpace1
	
/* 	func2();  */
	func3();
	return 0;
}

file2 (namespace_def_used2.cpp)

#include <stdio.h>

namespace NameSpace2
{
	void func3(void)
	{
		printf("func3 in the other file!\n");
	}
}

file3 (TestNameSpace.h)

//declare func3 in the other file
namespace NameSpace2{void func3(void);};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值