博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
namespace关键字-1
阅读量:2031 次
发布时间:2019-04-28

本文共 2052 字,大约阅读时间需要 6 分钟。

目录


例1:命名空间中的类

#include
#include
#include
#include
#include
#include
#include
#include
#include
/*size_t*/#include
#include
#include
//abort()using namespace std;namespace rong{ template
class list_item{ public: list_item(elemType value, list_item *item = 0) :_value(value){ if(!item) _next = 0; else{ _next = item->_next; item->_next = this; } } elemType value(){return _value;} list_item *next(){return _next;} void next(list_item *link){_next = link;} void value(elemType new_value){_value = new_value;} void display(){cout<<_value<
*l = new list_item
(3); using namespace name1; using namespace name2; cout<
<

例2:命名空间中的变量

#include
#include
using namespace std;namespace rt{ int r = 100; int t = 200;};using namespace rt;int main(int argc, char *argv[]){ rt::r = 98; int r = 99; cout<
<
<

例3:命名空间里的函数

#include
#include
using namespace std;namespace rt{ int r = 100; int t = 200; template
void print(elemType r, elemType t) { cout<
<
<
(rt::r, r); rt::print
(string("rong"), string("tao")); return 1;}

例4:命名空间里的函数

#include
#include
using namespace std;namespace rt{ int r = 100; int t = 200; template
void print(elemType r, elemType t) { cout<
<
<
(rt::r, r); rt::print
(string("rong"), string("tao")); rt::R::print(); rt::R::print("rongtaoshinidaye"); return 1;}

例5:匿名namespace

#include
#include
using namespace std;//函数swap()只在此文件中可见namespace {void swap(){/*...*/};}int main(int argc, char *argv[]){ return 1;}

例6:using

#include
#include
using namespace std;namespace China_University_of_Petrolume{int a = 999;}int main(int argc, char *argv[]){ namespace upc = China_University_of_Petrolume; cout<
<

 

转载地址:http://pdtaf.baihongyu.com/

你可能感兴趣的文章
LeetCode003.Longest Substring Without Repeating Characters
查看>>
LeetCode019. Remove Nth Node From End of List
查看>>
LeetCode130. Surrounded Regions (思路及python解法)
查看>>
LeetCode179. Largest Number(思路及python解法)
查看>>
LeetCode227. Basic Calculator II(思路及python解法)
查看>>
LeetCode166. Fraction to Recurring Decimal(思路及python解法)
查看>>
LeetCode454. 4Sum II(思路及python解法)
查看>>
LeetCode395. Longest Substring with At Least K Repeating Characters(思路及python解法)
查看>>
LeetCode268. Missing Number
查看>>
iOS组件化开发一远端私有库建立(二)
查看>>
我们应当怎样做需求分析
查看>>
问题账户需求分析
查看>>
《uml大战需求分析》阅读笔记05
查看>>
远程办公之:向日葵X 使用教程
查看>>
Varnish4.x配置文件详解
查看>>
Roundcube Webmail 安装配置图文详情
查看>>
Mysql innodb_flush_log_trx_commit 简单调优
查看>>
Piranha web 界面LVS DR 模式配置图文详解
查看>>
Piranha LVS DR 模式 HA 集群配置
查看>>
Apache RewriteCond RewriteRule 跳转故障解决
查看>>