0

I have a template class that has two nested classes in it, and one is derived from another:

template <typename T>
class SuperList
{
public:
    using List = typename std::list<T>;

    struct BaseIterator
    {
        explicit BaseIterator(typename List::iterator iterator):
            iterator_(iterator) {}

        typename List::iterator iterator_;
    };

    struct DerivedIterator : public BaseIterator
    {
        explicit DerivedIterator(typename List::iterator iterator):
            BaseIterator(iterator) {}

        void test() {iterator_;};
    };
};

It does not compile:

error: 'iterator_' was not declared in this scope void test() {iterator_;};

I don't understand, why the DerivedIterator doesn't see a member from the base class.

Ivan
  • 139
  • 1
  • 10
  • Problem solving tip: if you think it has something to do with nested classes, remove the nesting and see if the problem goes away. – juanchopanza Dec 10 '17 at 14:20
  • The answer is somewhere in §17.6.2 of the ISO standard, but you've got a really complicated case here. The solution is easier: writing `BaseIterator::iterator_` or `this->iterator_` should make the error go away. – Christian Hackl Dec 10 '17 at 14:28
  • @juanchopanza: Removing the nesting changes the situation, because the dependent name here depends on the template parameter of the enclosing class. Removing the nesting removes the genericity and makes the error go away. – Christian Hackl Dec 10 '17 at 14:31
  • @ChristianHackl The nested classes are class templates. So to removing the nesting only would mean writing the other classes as templates. The idea being to change only one thing at a time. Or, make the top level class a non-template and see the problem go away ==> the problem is not the nesting. – juanchopanza Dec 10 '17 at 15:42
  • @juanchopanza: *"So to removing the nesting only would mean writing the other classes as templates."* - Of course. My point was that this just isn't so obvious. IOW, it's not obvious to someone not very experienced with C++ templates how that "one thing" can be further separated. And even so, in theory that case could be covered by other rules in the standard. – Christian Hackl Dec 10 '17 at 15:46
  • @ChristianHackl I don't think it is an issue with domain knowledge. There are a bunch of things that can be tried to get a better understanding of a problem like the one shown here. Inheritance of nested classes of a class template isn't the simplest system around after all. – juanchopanza Dec 10 '17 at 15:50

0 Answers0