C ++ basics 3

Source: Internet
Author: User

Polymorphism:

Operator overload

The operator overload is implemented by creating the operator function operator. Example: complex operator + (complex A, complex B ){}

Generally, you can use the following two methods after using the member function to overload the binary operator +:

AA + BB or AA. Operator + (bb)

 

Pointer relationship between base class and derived class

1. The Declaration refers to a pointer to a base class object that can point to its public-derived object, but cannot point to its private-derived object.

2. A pointer to a derived class object cannot be directed to its base class object.

3. the Declaration refers to a pointer to the base class. When it points to an object of a public derived class in the current period, it can only be used to directly access the members inherited from the base class in the derived class, you cannot directly access the Members defined in the public derived class.

 

Virtual Functions

A virtual function must be a member function of its class, not a friend function or a static member function. However, a virtual function can be declared as a friend function in another class.

 

Pure virtual functions

Virtual void show_area () = 0

If a class has at least one pure virtual function, the class is called an abstract class. An object of an abstract class cannot be declared, but a pointer can be declared or referenced. This pointer can point to its derived class to implement polymorphism.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.