实施变量创建

时间:2014-05-06 18:57:05

标签: c++ constructor

在c ++中,我有一个班级,比如T。将对象构造为T t();而不是T();是有意义的。可以阻止第二个版本吗?

1 个答案:

答案 0 :(得分:-1)

您可以使用

T t; // invokes T() implicitly (t object is created on stack)
T* t = new T(); // explicitly (object is created on heap, pointer t to that object is on stack)

但是

T t(); // declares function t of a return type T