在C ++中实例化对象的不同方法 [英] Different methods for instantiating an object in C++
本文介绍了在C ++中实例化对象的不同方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这之间有什么区别:
Myclass *object = new Myclass();
和
Myclass object = new Myclass();
我看到很多C ++库如wxWidgets,OGRE等使用第一个方法...为什么?
I have seen that a lot of C++ libraries like wxWidgets, OGRE etc use the first method... Why?
推荐答案
第二个错误!
MyClass object;
这将工作。
关于如何在这两种可能性之间进行选择,它主要取决于你的对象应该活多久。有关详情,请参见此处。
Now, concerning how to choose between these two possibilities, it mainly depends on how long your object should live. See there for a thorough answer.
这篇关于在C ++中实例化对象的不同方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文