dimanche 24 septembre 2023

How to make several levels of nested classes work inside a template class in C++? [closed]

I have to put a nested class inside a template class, then I have to put another nested class inside already nested class, and so on. However, only the very first class is generic. I've tried to do this in several ways, and yet, that has resulted in errors. So, what's the right way to make those classes work correctly?

template <typename T>
class Outer {
    class Middle;
    Middle* _pMiddle;
};

template <typename T>
class Outer<T>::Middle {
    class Inner;
    Inner* _pInner;
};

template <typename T>
class Outer<T>::Middle::Inner {
    void DoStuff();
};

template <typename T>
void Outer<T>::Middle::Inner::DoStuff() {
}

I've read this and this questions, they haven't given me a straightforward solution that I need. Sadly, I'm not good in C++, and I have no time and real goal to learn it, I just have to make that relation of three (or even more) classes work to implement the real stuff I'm interested in here.

PS I'm using C++11.

Aucun commentaire:

Enregistrer un commentaire