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?
}
};
CodePudding user response:
That code of yours seems like it should not compile:
template <class T>
class Class2<T>::NestedClass2 final : Class2<T>::NestedClass1
Class2
does not have any NestedClass1
in it.
It should be like that if I understood you correctly:
template <class T>
class Class2<T>::NestedClass2 final : Class1<T, int>::NestedClass1
CodePudding user response:
I am sorry for this silly question, because I have just checked this decision once more, and it seems to compile and work. The only problem is Visual Studio says, that I can't access base classes members (it simply doesn't show them), but I still can.