I have an abstract class like so:
class A
{
public:
void func() = 0;
};
Can I force its implementations to have a nested iterator class too?
#include <iterator>
template<typename T>
class A
{
public:
class Iterator : public std::iterator<std::forward_iterator_tag, T>
{
};
virtual Iterator begin() const = 0;
virtual void func() = 0;
};
template<typename T>
class B : public A<T>
{
public:
B() {}
class Iterator : public std::iterator<std::forward_iterator_tag, T>
{
};
Iterator begin() const
{
return Iterator();
}
virtual void func()
{
}
};
int main()
{
B<int> b;
}
I just want to know if this is possible, and if it is, what am I missing? Since the iterator class will depend on how the class A is implemented, I don't know if a formal implementation is possible.