For practice, I am trying to make a recursive directory parser.
For the sake of parsimony, I want to contain the result recursively too, e.g.:
1 class CDirectory
2 {
3     private:
4        std::string name;
5        std::vector<CDirectory> subDirectories
6    public:
7        //Various things, constructors etc. go here
8 }
However, I see here that line 5 is not supported behavior - "The C++ Standard (2003) clearly says that instantiating a standard container with an incomplete type, invokes undefined-behavior."
What, then, do I do? Is there no way to make an object contain a list of similar objects? If nothing else, I know that it is by no means illegal to make a vector of vectors, so that's an object that contains itself.
Boost has containers that support incomplete types. You can use one of these.
#include <boost/container/vector.hpp>
class CDirectory
{
   private:
       std::string name;
       boost::container::vector<CDirectory> subDirectories
   public:
       //Various things, constructors etc. go here
};
                        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