Note the differences between C ++ and C # references.

Source: Internet
Author: User

C # has been used more, and has recently returned to C ++ programming. Some fatal differences are found. If you do not pay attention to them, some inexplicable bugs may occur. The reference type is one of them.

In C #, references are similar to pointers, except for the value type (INT, float, struct, etc. It is a variable on the stack. It points to a specific instance on the stack and can be changed at will.

In C ++, a reference is just an alias of a variable. It needs to point to an instance during initialization, and then its operation is equivalent to modifying the original Instance. In most cases, it is possible to change the reference usage like C:

Classa a1, a2;
Classa
& A = A1;
A
= A2;

 

Do not think that A is now a reference of A2. The last sentence is to assign the value of A2 to A1!

 

I would like to dedicate this article to C #'s proficiencyProgramEmployee

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.