Possible Duplicate:
Do the parentheses after the type name make a difference with new?
Whats the difference between the following initialisations? In the tutorial, it is as in case #1 but does it make any difference if i use the #2 way below?
struct X
{
X() {}
int x;
};
int main()
{
std::auto_ptr<X> p1(new X); // #1
std::auto_ptr<X> p2(new X()); // #2
}
The smart pointer doesn’t make any difference here. Both smart pointers are initialized in the same way, with a pointer to
X. The difference is howXis initialized. If there is a difference and what the difference is depends on howXis defined. This answer has an excellent description of what happens in different cases. In this case sinceXhas a default constructor they get initialized the same. However if there were no default constructor they would be initialized differently.