Differences between heavy load, overwrite, and hide

Source: Internet
Author: User

I often see this problem in csdn. How can I differentiate three people? I have already found a complete answer from the Forum. Now I will summarize it myself to help you better understand the problem and hope it will be useful to you.

Overload:

This is not a new concept. It is an important concept in C ++ (not allowed in C). The feature is that the same function name is allowed, you can specify different parameters or return values.

Here, the overload is for classes in C ++, and the class overload is exactly the same as previously mentioned.

Features: 1. Within the same class

2. Same Function Name

3. Different Parameters

Overwrite:

Coverage is a new concept proposed by C ++ object-oriented system. What if coverage is implemented? This is what we often call polymorphism. Implemented through a virtual function table, the base class uses virtual to declare a function as a virtual function, and creates a virtual function table. If the subclass overrides this function, the pointer of the subclass instance points to the rewritten function. This leads to the fact that the related instance (subclass, base class) has different effects on the same interface call, which is called polymorphism. Polymorphism is an advanced feature of C ++.

Features: 1. In different classes (one in the subclass and one in the parent class)

2. The basic functions must be declared using virtual declarations. The subclass functions are optional.

3. function name, parameters must be the same

Hide:

Hiding is a phenomenon, which is also a feature. In C ++, The subclass allows the caller to not see the function of the same name as the parent class. That is to say, the subclass cannot use the function of the same name as the parent class, this phenomenon is called hiding.

Features: 1. In different classes (one in the subclass and one in the parent class)

2. Same Function Name

2. If the base class function uses virtual, The subclass function must have different parameters.

4. If the base class is not virtual, The subclass function can be identical or different from the base class function.

Summary:

1. Overload: view parameters (parameters)
2. Hide: Call whatever you use (the hidden function of the base class is not visible to the subclass)
3. Overwrite: Call the derived class (which pointer is used to call)

If you have any questions, please leave a message.

 

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.