difference between new Test(); and new Test;

A

Anarki

#include <iostream>
using namespace std;

class Test
{
public:
Test()
{
cout << "Hello" << endl;
}
};
int main()
{
Test *p = new Test; //Statement 1
Test *q = new Test(); //Statement 2
return 0;
}

I want to know is there any difference between the Statement 1 and
Statement 2? If so what is it? please explain
 
A

Alf P. Steinbach

* Anarki:
#include <iostream>
using namespace std;

class Test
{
public:
Test()
{
cout << "Hello" << endl;
}
};
int main()
{
Test *p = new Test; //Statement 1
Test *q = new Test(); //Statement 2
return 0;
}

I want to know is there any difference between the Statement 1 and
Statement 2?

No, but there would have been if Test was a POD type.

If so what is it? please explain

For a POD type statement 2 would have zero-initialized the object rather
than leaving it with indeterminate values.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top