命名空间namespace:
C++的命名空间的使用:https://www.cnblogs.com/wanghuixi/p/6887390.html
命名空间:https://www.runoob.com/cplusplus/cpp-namespaces.html
C++教程的一个网站,包括很多基础知识:https://www.runoob.com/cplusplus/cpp-tutorial.html
示例1:
#include <iostream>
using std::cout;//1
int main ()
{
cout << "std::endl is used with std!" << std::endl;//2
return 0;
}
/*********************或者********************/
#include <iostream>
using namespace std;//1
int main ()
{
cout << "std::endl is used with std!" << endl;//2
return 0;
}
示例2:
#include <iostream>
using namespace std;
namespace A
{
int a = 100;
namespace B //嵌套一个命名空间B
{
int a =20;
}
}
int a = 200;//定义一个全局变量
int main(int argc, char *argv[])
{
cout <<"A::a ="<< A::a << endl;
cout <<"A::B::a ="<<A::B::a << endl;
cout <<"a ="<<a << endl;
cout <<"::a ="<<::a << endl;
int a = 30;
cout <<"a ="<<a << endl;
cout <<"::a ="<<::a << endl;
return 0;
}
结果:
A::a =100
A::B::a =20
a =200 //全局变量a
::a =200
a =30 //局部变量a
::a =200
即:全局变量 a 表达为 ::a,用于当有同名的局部变量时来区别两者。
****************************************************************************************************************
const:
const用法:https://www.cnblogs.com/xudong-bupt/p/3509567.html
****************************************************************************************************************
好难啊,我真的完全看不懂tmc13的代码【哭哭】,补了一些小知识依旧没什么大用啊,他这代码怎么写出来的,也太复杂了吧(╥╯^╰╥),都不知道该从哪里下手。o(╥﹏╥)o
真的好难啊。。。。。。。。。啊。。。。。。。。。。。。。。。。。。。。。。。。。。。。【抱头痛哭】