Good day people, I'm stuck with a silly C++ problem.
Let's say I have an iterator called it1 that goes through the values of a vector containing pointers to a class, we'll call it C:
std::vector<C*>::iterator it1;
But C is not alone: it has many subclasses, which share the same attributes and methods I'm looking for with it1, although their implementations may or may not differ. What should I do if I wanted the iterator to iter though elements (or better, pointers) not only of class C, but also of its children?
What I thought was something using templates, although that would make the iterations unsafe since I don't know how to limit the template only to C and its subclasses. Any suggestions?
Edit: yes, I was talking about a recursive data structure.
Edit2: Well, it seems like it wasn't the iterator's fault after all. My code worked fine, I asked the question because I was going to implement changes to it and I was unsure about what to do. Sorry if that was unclear.