0

Why would a class be redeclared in another class?

I came across this syntax while i was reading about Tree data structures but i couldn't figure out why it was written like that. If you understand why please help me out. template <typename T> class Node { //.... }; template <typename T> class Tree { private: class Node; //.... }; Why was class Node placed in Tree instead of just a Node object?

3rd May 2019, 12:20 PM
Mensch
Mensch - avatar
6 Antworten
+ 3
~ swim ~ In that example there is a definition for class Node before the definition of class Tree. When they come in such sequence, is a forward declaration still necessary? I thought forward declaration was for the same purpose with that of function prototype (is it?) And to clear my doubt about declaration and definition, this is how I see it, cmiiw : ) class A; // declaration class A // definition { // member definition };
3rd May 2019, 2:06 PM
Ipang
+ 3
~ swim ~ Big Thanks for clearing my doubt 👍
3rd May 2019, 2:20 PM
Ipang