2

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

In C++, what is the difference between these two statements?

Class clg
{

  public :

  int x,y,z;

};

int main(void)

{

  clg *ptrA = new clg;    //

  clg *ptrB = new clg();  //  what is the importance of "()"  ???

 return 0;

}
Community
  • 1
  • 1
Uday
  • 21
  • 1
  • 1
    Duplicate of [Do the parentheses after the type name make a difference with new?](http://stackoverflow.com/questions/620137/do-the-parentheses-after-the-type-name-make-a-difference-with-new) – James McNellis Apr 10 '11 at 08:19
  • Possible duplicates: [Do the parentheses after the type name make a difference with new?](http://stackoverflow.com/questions/620137/do-the-parentheses-after-the-type-name-make-a-difference-with-new), [Not using parentheses in constructor call with new (c++)](http://stackoverflow.com/questions/5211090/not-using-parentheses-in-constructor-call-with-new-c), [Is no parentheses on a C++ constructor with no arguments a language standard?](http://stackoverflow.com/questions/2318650/is-no-parentheses-on-a-c-constructor-with-no-arguments-a-language-standard) – Cody Gray - on strike Apr 10 '11 at 08:20

1 Answers1

-1

Practically? Nothing, for a class.

Under the hood, one calls an explicit constructor of the class, whereas the other calls the default constructor. In any case, chances are both your constructors will do the same thing(in the above case, they will, though you could theoretically call the copy constructor), though this is not true for POD types.

Ben Stott
  • 2,218
  • 17
  • 23