2

Possible Duplicate:
Do the parentheses after the type name make a difference with new?

I have C/C# background. I'm learning C++.

In C++, there're so many constructor forms. I'm confusing about them. These are my understandings. Is this correct?

struct T {};

// #1
T* a = new T;  // Regular form. Just allocate memory.
// My understanding in C.
T* a = malloc(sizeof(T)); 

// #2
T* a = new T(); // #1 + Calling constructor.
// My understanding in C.
T* a = malloc(sizeof(T));
T_ctor_func(a);
Community
  • 1
  • 1
eonil
  • 83,476
  • 81
  • 317
  • 516

0 Answers0