C++(2013.12.3)总结补漏

  1.头文件兼容C/C++

1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4 
5     int add(int, int);
6 
7 #ifdef __cplusplus
8 }
9 #endif
add.h

    2.public : 

        1.不属于类的顶层函数(比如main)可以访问

        2.相同类的成员函数可以访问

        3.不同类的成员函数也可以访问

  protected :

        1.不属于类的顶层函数(比如main)不可以访问

        2.相同类的成员函数可以访问

        3.不同类的成员函数不可以访问

        4.子类的成员函数可以访问

  private :

        1.不属于类的顶层函数(比如main)不可以访问

        2.相同类的成员函数可以访问

        3.不同类的成员函数不可以访问

  3.重载运算符一般有两种形式 : 

    1.不属于类的顶层函数

      Complex operator +(const Complex& a, const Complex& b);

       a + b  --> operator +(a , b);

    2.属于类的成员函数

      Complex operator + (const Complex &b);

        a + b  --> a.operator(b);

    3.特殊运算符重载 : 

      ostream& operator << (ostream &out, const Complex &a);     :只能以顶层函数形式重载

      Complex & operator = (const Complex & a);  :只能以类的成员函数形式重载

  注意 : 运算符重载只改变运算方法和运算结果,运算符的优先级和结合行保持不变

    4.  几种特殊的重载

      T * operator -> ()

      const T * operator->() const

      T& operator * ()

      const T & operator*() const

      T& operator [] (int index)

      cosnt T & operator [] (int index) const

      T & operator ++ ()  :前置++

      T & operator ++ (int)   :后置 ++

    5. The big three

      构造函数,析构函数,和赋值函数是类最重要的函数,被称为The big three

      explicit  显式的

    6.继承 :

        隐藏 :派生类隐藏基类中的同名函数,与参数无关

     多态 的三要素:

        1.要有类的继承关系

        2.父类子类中要有同名的虚函数(参数,返回值必须一样)

        3.通过父类的指针或父类的引用去调用这些同名方法

    7.

     

原文地址:https://www.cnblogs.com/cxw825873709/p/3455224.html