Possible Duplicate:
Do th开发者_JAVA技巧e 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;
}
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.
精彩评论