Const inline function

Source: Internet
Author: User
Tags constant
Const constants
1, the Declaration of initialization, after which can no longer be changed const int i;
2. Pointer constants and constant pointers:
const INT * p; What p means cannot be changed.
int * Const;p address cannot be changed
Discriminant: With * as the dividing line, const on the left the data is constant, const on the right, the pointer is constant
3, the parameter is constant: void f (const int p); p cannot be changed
For example: void f (const int p) {
int & m=p;
m++;//error, M is a p reference, and p represents the same data and cannot be changed
}
4. The return value is constant: const int F (), at which point the return value cannot be modified as a left value.
F () =6;//. Error, return constant, cannot be modified
5. The const pointer cannot be assigned to a very measure pointer to prevent modification.
6. Constant Objects const X obi; constant objects can only access constant member methods.
7, constant function void f () const; The function cannot modify members in a class unless you use the mutable modifier. For 6 of the situation can have obj.f ();

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.