I have a class called Base which holds internally a container of objects of type SomeType.
Then I create class Derived: protected Base.
Now I want to create custom iterators in the Derived class to offer the user the ability to iterate over the objects in the container in the Base class. The thing is that SomeType offers more features that I want to give i.e. I want to hide some of the functions offered in SomeType and possibly add some extra data fields and functions.
So one thing I tried to do is wrap SomeType like this:
class AnotherType{
private:
SomeType& object;
public:
//Make visible what I want
}
And then inside the operator*() in the iterator create a new AnotherType object and return it.
My problem with this is that then, I can't do this:
Derived d;
for(auto& object: d)
// Use object however i like.
Note the "&" in auto.
One other possible solution, in the case that I won't add any extra data fields, would be to use something like this. But as I see it is undefined behaviour.
Any ideas?