2017.2.21
1.const成员函数不能调用非const成员变量,可以调用mutable成员变量
2.nullptr和NULL区别
3.类的指针和引用
改变指针指向用二级指针或指针的引用(*&)
4.malloc/free 和new/delete区别
malloc/free 只会分配内存,释放内存,不会对内存进行操作
new/delete 自动调用构造析构
5.运算符重载
1.成员函数
1 mycomplex operator +(mycomplex adddata) 2 { 3 mycomplex temp; 4 temp.x = this->x + adddata.x; 5 temp.y = this->y + adddata.y; 6 return temp; 7 }
2.友元函数:可以处理不同类型
1 friend mycomplex operator +(mycomplex adddata1, mycomplex adddata2);//友元函数 2 mycomplex operator +(mycomplex adddata1 ,mycomplex adddata2) 3 { 4 mycomplex temp; 5 temp.x = adddata1.x + adddata2.x; 6 temp.y = adddata1.y + adddata2.y; 7 return temp; 8 }
3.输入输出重载
1 friend ostream & operator <<(ostream & out, mycomplex & Complex); 2 friend istream & operator >>(istream & in, mycomplex & Complex); 3 ostream & operator <<(ostream & out, mycomplex & Complex) 4 { 5 6 out << Complex.x << "+" << Complex.y << "i" << std::endl; 7 return out; 8 } 9 istream & operator >>(istream & in, mycomplex & Complex) 10 { 11 cout << "请输入X,Y" << endl; 12 in >> Complex.x >> Complex.y; 13 return in; 14 }
4.++前增,后增重载
1 TDPoint operator++();//成员函数重载前置运算符++ 2 TDPoint operator++(int);//成员函数重载后置运算符++ 3 friend TDPoint operator++(TDPoint& point);//友元函数重载前置运算符++ 4 friend TDPoint operator++(TDPoint& point,int);//友元函数重载后置运算符++
5.赋值运算符重载(深拷贝和浅拷贝)
6.下标重载
1 char operator [] (int i);