本质:引用的本质在C++内部实现是个指针常量

    1. //发现是引用,转换为int * const ref = &a;
    2. void func(int& ref)
    3. {
    4. ref = 100; //ref是引用,转换为*ref = 100
    5. }
    6. int main()
    7. {
    8. int a = 10;
    9. //自动转换为 int * const ref = &a; 指针常量是指针指向不可改,也说明为什么引用不可更改
    10. int& ref = a;
    11. ref = 20; //内部发现ref是引用,自动帮我们转换为: *ref = 20;
    12. cout << "a:" << a << endl;
    13. cout << "ref:" << ref << endl;
    14. system("pause");
    15. return 0;
    16. }