struct Element{
Element() {}
int data = NULL;
struct Element* right, *left;
};
or
struct Element{
Element() {}
int data = NULL;
Element* right, *left;
};
I was working with binary trees and I was looking up on an example. In the example, Element* right
was struct Element* right
. What are the differences between these and which one would be better for writing data structures?
I was looking up from this website: https://www.geeksforgeeks.org/binary-tree-set-1-introduction/
In C++, defining a class also defines a type with the same name so using
struct Element
or justElement
means the same thing.You rarely have to use
struct Element
(other than in the definition) in C++.There is however one situation where you do need it and that is when you need to disambiguate between a type and a function with the same name: