在:http://www.horstmann.com/ccj2/ccjapp3.html,在A3.4下.对象,提到以下内容:
在C++中,对象变量包含值,而不是对象引用
你能澄清这一点吗?并且,它只是pointer
在C++中持有对象引用吗?
我们可以在这说这object reference
是object address
吗?
谢谢.
你能澄清这一点吗?
最好通过与Java或C#进行比较来理解:
MyClass a = new MyClass; // creates an instance.
MyClass b = a; // we still have one instance of MyClass in memory
Run Code Online (Sandbox Code Playgroud)
与C++相反:
MyClass a; // a *is* an instance of MyClass.
MyClass b = a; // we make a copy of a, now there are *two* instances of MyClass.
Run Code Online (Sandbox Code Playgroud)
而且,只有C++中的指针才能保存对象引用吗?
不,也是参考.
我们可以在这里说对象引用是对象地址吗?
不,如果您的意思是A&
参考,那么它就是一个实现细节.您也可以使用与C#类似的引用语义来实现对象.xml_node
在pugixml库中就是一个例子:
xml_node root = ...;
xml_node root2 = root; // doesn't copy the document
// root2 refers to the same object as root.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11983 次 |
最近记录: |