Reputation:
LinkedListNode* toSort = new LinkedListNode((MTNode*)0, (LinkedListNode*)0,
(LinkedListNode*)0);
can someone give me detail explanation on how to read this code?? especially, I don't understand those zeros in
(MTNode*)0, (LinkedListNode*)0,(LinkedListNode*)0
Upvotes: 2
Views: 48
Reputation: 145224
Literal 0 designates a nullpointer where a pointer is expected. The casts to the relevant pointer types are ¹redundant. In modern C++ just write nullptr
, and preferably use curly braces for constructor invocations, i.e.
auto* toSort = new LinkedListNode{ nullptr, nullptr, nullptr };
Notes:
¹ Unless there are two or more overloads that accept literal 0 arguments; in that case the casts can serve to disambiguate the call, choose the right constructor.
Upvotes: 3
Reputation: 170055
In a bit more modern c++, it would look like:
LinkedListNode* toSort = new LinkedListNode(nullptr, nullptr, nullptr);
Does it make more sense now? It just passes null values for each expected pointer.
Upvotes: 4