I just wanted to confirm the difference here, take this as an example:
class Gate
{
public:
Gate(); //Constructor
void some_fun();
private:
int one, two;
ptr p1;
Gate* next;
};
typedef Gate* ptr;
Gate::Gate()
{
one = 0;
two = 0;
}
void Gate::some_fun()
{
p1 = new Gate;
p1 = p1->next;
p1 = new Gate();
}
In my example, I have created 2 new nodes of “Gate” and the only difference between them is that the first node does not have the variables “one and two” initialized, while the second one does.
C++ has two classes of types: PODs and non-PODs (“POD” stands for “plain old data” … a somewhat misleading hint).
For non-PODs, there is no difference between
new Tandnew T(). The difference only affects PODs, for whichnew Tdoesn’t initialise the memory, whereasnew T()will default-initialise it.So what are PODs? All built-in C++ types (
int,bool…) are.Furthermore, certain user-defined types are as well. Their exact definition is somewhat complicated but for most purposes it’s enough to say that a POD cannot have a custom constructor (as well as certain other functions) and all its data members must themselves be PODs. For more details, refer to the linked FAQ entry.
Since your class isn’t a POD, both operations are identical.