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 T
and new T()
. The difference only affects PODs, for which new T
doesn’t initialise the memory, whereas new 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With