C + + Primer Chinese version of Learning notes (11) __c++

Source: Internet
Author: User

12th Chapter Class

1 data abstraction is a programming (and design) technology that relies on interface and implementation separation. Encapsulation is a technique that combines low-level elements to form new, high-level entities.

2 the only chance to initialize a const or reference and a class-type data member without a default constructor is in the constructor initialization list.

3 Implicit type conversions: a constructor that can be invoked with a single argument defines an implicit conversion from the formal parameter type to the class type

Explicit only works on constructors to suppress implicit conversions.

4 There are three advantages to using a static member instead of a global object.

1 The name of the static member is in the scope of the class, so you can avoid conflicts with members of other classes or global object names.

2) can implement encapsulation. Static can be a private member and the global object may not.

3 It is easy to see through the reading program that the static member is associated with a particular class. This visibility can clearly show the programmer's intentions.

5 each static data member is an object associated with a class and is not associated with an object of that class.

6 static member functions do not have this pointer, cannot be declared as const (static data members can), cannot be declared as virtual functions, and cannot be used directly by non-static members.

7 The type of a static data member can be the class type to which the member belongs. A non-static member is qualified to be declared as a pointer or reference to its own class object:

Class Bar

{

Private

Static Bar mem1;

Bar *mem2;

Bar mem3;

}

8 Generally, static members of a class, like regular data members, cannot be initialized in the definition body of a class. is typically initialized at the time of definition.

Exception: As long as the initializer is a constant expression, an integer const static data member can be initialized in the class's definition body. However, you must still define outside the definition body of the class without specifying an initial value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.