-1

In c++, I have a class, say T. It is meaningful to construct an object as T t(); but not as T();. Can the second version be blocked?

user66081
  • 420
  • 7
  • 15

1 Answers1

-1

You can use

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)

But

T t(); // declares function t of a return type T
Nenad
  • 335
  • 1
  • 7