Const after a C + + function

Source: Internet
Author: User
A function acgepoint3dstartpoint () Const;const is there any difference between the back and the front?
==> accurately says that const is the object that modifies this point, for example, we define CLASSA{PUBLIC:F (int);}; Here the F function actually has two parameters, the first one is A*const this, the other is the int type parameter if we do not want the F function to change the value of the parameter, we can change the function prototype to F (constint), but if we do not allow F to change the object of this point? Because this is an implicit parameter, const cannot directly modify it, it is added to the back of the function, indicating that the type of this is Consta *constthis. The const modifier *this is essentially, as to say "means that the member function does not modify the data of the class." Otherwise it will compile the error "such a statement is only a phenomenon, the root cause is because *this is a const type of

In a normal non-const member function, the type of this is a const pointer to the class type. You can change the value that this is pointing to, but you cannot change the address saved by this. In the const member function, the type of this is a const pointer to the Const class type object. You can neither change the object that this is pointing to nor change the address saved by this.


http://blog.csdn.net/zcf1002797280/article/details/7816977

Const after a C + + function

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.