It is absolutely possible, but "infinite loop" is also possible, under the condition of the sufficient idiocy of the implementation :-). If you do it in the simplest possible way, it will immediately work, by a very simple reason: at the moment of construction, the vector contains zero elements:
class VectorOfElementsWithVector {
public:
void Add(VectorOfElementsWithVector &element) { m_vector.push_back(element); }
private:
std::vector<VectorOfElementsWithVector> m_vector;
};
VectorOfElementsWithVector container, element;
container.Add(element);
Moreover, you could do the same with an array, but then you will need to use the heap. Only if you try to construct the instance of a similar class attempting to make sure that each vector has at least one element right in the constructor, it will cause infinite
recursion.
—SA