difference between new Test(); and new Test;



 DEVELOP > c-Plus-Plus > difference between new Test(); and new Test;

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Anarki"
Date: 12 Aug 2007 05:19:17 AM
Object: difference between new Test(); and new Test;
#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
.

User: "Alf P. Steinbach"

Title: Re: difference between new Test(); and new Test; 12 Aug 2007 05:22:45 AM
* 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.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER