栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++命名空间(一)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++命名空间(一)

一、namespace命名空间
  1. 命名空间用途:解决名称冲突
  2. 命名空间下可以存放 : 变量、函数、结构体、类…
  3. 命名空间必须要声明在全局作用域
  4. 命名空间可以嵌套命名空
  5. 命名空间是开放的,可以随时将新成员添加到命名空间下
  6. 命名空间可以匿名的
  7. 命名空间可以起别名 使用示例

main.c

#include 
#include"start1.h"
#include"start2.h"
#include"start3.h"

using namespace std;

namespace A {
    int A_a=10;
    int A_b=20;
}

void ns() {
    using namespace s1;
    using namespace A;
    test();
    cout << A_a << endl;
}

int main()
{
    bool tag = true;
    namespace ABC = A;

    s1::test();
    s2::test();
    s3::s4::test();

    cout << "Hello World!"< 

start3.h、start3.cpp

//start3.h
#pragma once
#include
using namespace std;

namespace s3 {
	namespace s4 {
		void test();
	}
}


//start3.cpp
#include"start3.h"

void s3::s4::test() {
	cout<<"start 3" << endl;
}

start2.h、start2.cpp

//start2.cpp
#pragma once
#include
using namespace std;

namespace s2
{
	void test();
}


//start2.h
#include"start2.h"

void s2::test() {
	cout<<"start 2" << endl;
}

start1.h、start1.cpp

//start.h
#pragma once
#include
using namespace std;

namespace s1
{
	void test();
}

//start1.cpp
#include"start1.h"

void s1::test() {
	cout << "start 1"< 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/675708.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号