C ++ class study notes

  1. Friend function can access the object's private part
    friend There are three:
    • Friend function
    • Tomomoto类
    • Friend member function
  2. Friend function without the use of class qualifier
  3. Friend function without changing parameters, are generally not added after const
  4. For member functions, a number of operations by this pointer is implicitly passed, the other operand is passed as an argument explicitly; for a friend function, both operands are passed as parameters, for example:

    Time operator+(const Time &t) const;
    friend Time operator+(const Time &t1,const Time & t2);
  5. State of the member is described in which the state of the object
  6. Accept only a constructor parameter defines the conversion from the parameter type to the class type. If the keyword explicitdefines this constructor, it can only be used to explicitly convert otherwise implicit conversion may also be used.

    Stonewt myCat;
    myCat = 19.6;           // 如果 Stonewt(double) 是 explicit 声明的,这不合法
    myCat = Stonewt(19.6);  // 显式转换
    myCat = (Stonewt)19.6;  // 旧版本的显式转换

    However, if and only if the conversion ambiguity does not exist, this will be a two-step conversion that is, if the class also defines a constructor Stonewt(long), the compiler rejected these statements may be noted: int can be converted as long or double, so the call there is ambiguity.

  7. Does not allocate memory when using the pointer indicates the object name. This is the knowledge a long time ago.

    int * arr;      // 没有内存之间, 只是一个指针
    int arr[10];    // 有内存空间
  8. Static class members staticfeatures: No matter how many objects are created, the program only creates a copy of a static class variable that is to say, all object classes share the same static member.

Guess you like

Origin www.cnblogs.com/count0/p/10926463.html