C + + Primer 12 Chapter Class

Source: Internet
Author: User

1. About const objects of a class

Const objects can only invoke member functions declared as const, which is also discussed in this CSDN blog .

The reason is because

The const object A calls the non-const function f, f because there is no const constraint to modify the members within the A object, does that violate the original intent of the a declaration const?

Conversely, it is possible to call a const function on a non-const object.

2. Const-based overloading

The member functions of the Const modifier can be described in this Sina blog!

A member function can be overloaded based on whether the member function is const;

A function can be overloaded based on whether a pointer parameter is const.

eg

void Isnumber (const int&);

void Isnumber (int &);

void Isnumber (const int &) const;

3. Other uses of const

You can see this blog post

C + + Primer 12 Chapter 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.