Special issues when a derived class initializes a base class member

Source: Internet
Author: User

As follows:Code:Class basic <br/>{< br/> Public: <br/> int data; <br/> protected: <br/> PRIVATE: <br/> }; </P> <p> class son: Public Basic <br/>{< br/> Public: <br/> son (): Data (0) {}< br/> protected: <br/> PRIVATE: <br/> };

When initializing a base class member, use the constructor member to initialize the list. However, an error is prompted when the following method is used:

Error c2614: "son": Invalid member initialization: "data" is not a base or member

 

In fact, this prompt is incorrect, but the error should also be located, because if Initialization is used in this case, if the base class has a default constructor, and it also shows that the base class members are initialized, so... is it covered? Yes, so it cannot be initialized like this. You can only assign values to the constructor of the derived class or call the constructor of the base class.

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.