How C++ reference works

前端 未结 5 1133
别那么骄傲
别那么骄傲 2020-12-17 05:54

After working 15 years in C++ I found that I don\'t understand references completely...

class TestClass
{
public:
    TestClass() : m_nData(0)
    {
    }

    T         


        
5条回答
  •  北海茫月
    2020-12-17 06:50

    A good way is to compare references to pointers... (references are usually implemented the same way in assembly generally by using the ebx register). The main difference is that reference is constant after initialization...

    However, The line const TestClass& c = TestClass(); is parallel to const TestClass* const pc = &TestClass(); so the object will be create and destroyed on the stack, pc will still hold the same address.

提交回复
热议问题