Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ class initialization with and without parentheses [duplicate]

What is the difference between the following 2 two initializations?

class Pod {
public:
    int a, b;
};

Pod *p1 = new Pod;
Pod *p2 = new Pod();
like image 260
codefx Avatar asked Mar 17 '13 02:03

codefx


1 Answers

In the first case the object is left uninitialized, while in the second case the object is guaranteed to be value-initialized, which in this case as the type is POD it means zero-initialized

like image 57
David Rodríguez - dribeas Avatar answered Oct 05 '22 23:10

David Rodríguez - dribeas