#预处理指示符
预处理宏assert
内存泄漏指的是程序不具有某块内存的指针
指针和动态内存分配
类构造函数,函数重载,析构,引用,基类(父类,超类),派生类(子类)
双冒号 :: 操作符被称为域操作符 scope operator
protected private public
//头文件
#ifndef IntArrayRC_H #define IntArrayRC_H #include "IntArray.h" class IntArrayRC : public IntArray { public: IntArrayRC( int sz = DefaultArraySize ); IntArrayRC( int *array, int array_size ); IntArrayRC( const IntArrayRC &rhs ); virtual int& operator[]( int ); private: void check_range( int ); }; #endi
多继承和虚拟继承
怎样把 IntArray 类转换成 Array 类模板 下面是定义: template < class elemType > class Array { public: // 把元素类型参数化 explicit Array( int size = DefaultArraySize ); Array( elemType *array, int array_size ); Array( const Array &rhs ); virtual ~Array() { delete [] ia; } bool operator==( const Array& ) const; bool operator!=( const Array& ) const; Array& operator=( const Array& ); int size() const { return _size; } virtual elemType& operator[](int index){ return ia[index]; } virtual void sort(); virtual elemType min() const; virtual elemType max() const; virtual int find( const elemType &value ) const; protected: static const int DefaultArraySize = 12; int _size; elemType *ia; };
T为实际类型占位符
自定义模板类,自定义头文件
异常程序设计
try catch异常处理是顺序进行的
命名空间
namespace IBM_Canada_Laboratory { template <class elemType> class Array { ... }; class Matrix { ... }; // ... } namespace Disney_Feature_Animation { class Point { ... }; template <class elemType, int size> class Array { ... }; // ... }
数据类型:char string int shrot long float double longdaouble bool ,数组 复数 vector set map stac queue deque pair容器 类 变量 const 引用 枚举类型erum typedef volatile
指针的典型用法是构建一个链接的数据结构 例如树 tree 和链表 list 并管理在程序执行过程中动态分配的对象 以及作为函数参数类型 主要用 来传递数组或大型的类对象
算术运算符,逻辑运算符,赋值操作符,递增递减符,条件符,sizeof(), new delete语句,位操作符(bitset操作),优先级,类型转换
系统为每个程序都提供了一个在程序执行时可用的内存池 这个可用内存池被称为程序 的空闲存储区 free store 或堆 heap
vector<string>::iterator iter = text.begin(),迭代
链表类必须支持的操作是什么 用户必须能够插入 insert 或删除 remove 以及查 找 find 一个项 用户必须能够查询链表的长度 size 显示 display 链表 以及比较 两个链表是否相等 equality 另外 还要支持翻转 reverse 链表以及连接 concatenate 两个链表
命名空间
namespace Primer_Third_Edition { template<typename elemType> class list_item{ ... }; template<typename elemType> class list{ ... }; // ... }
顺序容器list vector deque
关联容器map set
deque两端插入和删除效率比vector高,随机访问和已知存储大小用vector,其他list