C++是1982年本贾尼博士在C的基础上扩充了面向对象的概念,发明的一种新的程序语言;
推荐书籍:1)初期:《C++程序设计》、《高质量程序设计指南——C++/C语言》;2)中期:《effective C++》(<--必读)、《C++ primer》(<--语法字典,不带plus);3)后期:《STL源码剖析》、《深度探索C++对象模型》
一、命名空间
为了解决命名冲突的问题,C++提出了命名空间的概念:
# include <stdio.h>
% 定义命名空间
namespace oxr
{
% 命名空间中可以定义变量、函数和类;
int sum = 0; % 变量
int add(int x,int y) % 函数
{
return x + y;
}
struct ooo
{
int val;
}
}
int main()
{
print("sum = %d", oxr::sum); % 其中::是域作用限定符
print("sum = %d", oxr::add(1,2));
struct oxr::ooo ooo1;
return 0;
}
命名空间还可以展开,这样就不用每次用的时候前面加前缀了
using namespace ooo;