Reputation: 21
I would like to have a template, which has nested class. Then I would like to have a template, which inherits the first template and also has a nested class. Then I would like this nested class to inherit his owner base nested class. I can do it, but I can't access members of the first nested class from another. What am I doing wrong, or is it impossible at all? Why? What have I do to fix the problem (if possible)/alternative decision (if impossible)?
template <class T, class T2>
class Class1
{
public:
class NestedClass1;
};
template <class T, class T2>
class Class1<T, T2>::NestedClass1
{
public:
void Do()
{
}
};
template <class T>
class Class2 : Class1<T, int>
{
public:
class NestedClass2;
};
template <class T>
class Class2<T>::NestedClass2 final : Class2<T>::NestedClass1
{
public:
void Do2()
{
this->Do(); // Why there is no "Do" in this?
}
};
Upvotes: 1
Views: 65
Reputation: 10979
That code of yours seems like it does not compile equally well on popular compilers:
template <class T>
class Class2<T>::NestedClass2 final : Class2<T>::NestedClass1
About it clang complains that Class2
does not have any NestedClass1
in it.
It technically has, as inherited nested class is nested class too, however clang disagrees in said context and so do tools that are built using clang's codebase.
Here is workaround that works on all three major compilers:
template <class T>
class Class2<T>::NestedClass2 final : Class1<T, int>::NestedClass1
Upvotes: 2