I have a class that looks like this:
// List.hpp
template<typename T>
class List {
...
private:
class Node;
};
And I want to put the full definition of List<T>::Node
into a separate file:
// Node.hpp
template<typename T>
class List<T>::Node {
...
};
My question is, what should I include in each file, and where to put the #include
s?
The simplest method (I think) is to include Node.hpp
at the end of List.hpp
, and not include anything in Node.hpp
. However, this makes Node.hpp
on its own not a complete file (say if I open it in an IDE or something there would be a lot of errors due to missing the definition of List<T>
). Also, I'm not sure if it's okay to put #include
s at the bottom of a file.
Assuming each file has its own include guard #define
, I can also include List.hpp
at the top of Node.hpp
(to make IDEs happy), and then include Node.hpp
at the bottom of List.hpp
again, but I don't know if that's a good idea.