In C ++, an error occurs when the parameter names and variable names in the same class are the same. There are two solutions:

Source: Internet
Author: User
Class {
Int P;
Void fun (INT p ){
P = P;
}
}

For example, in the preceding example, If you obtain the value of the integer Variable P of A Class Object in the future, the system will re-simulate a default value, such as-838232304.

There are two solutions: One is through the this pointer

Class {
Int P;
Void fun (INT p ){
This-> P = P;
}
}

 

2. Change the parameter name

 

Class {
Int P;
Void fun (INT P1 ){
P = p1;
}
}

 

 

This problem is generally not a problem in advanced languages, but in C and C ++, try to develop the habit of not having the same parameter name as the variable name.

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.