vendredi 22 avril 2022

Create an object of nested class in templated class

I am struggling with this, and would appreciate some help!

I have the following code:

#include <iostream>

enum Enum{A, B, C};

template<class T>
class classA
{
    public:

    template<Enum E = A>
    class innerClassA
    {
        public:
        innerClassA() {}
    };
};

template<class T>
class classB
{
    public:
    classB(){}

    template<Enum E = A>
    void foo() 
    {
        // using innerClassA= typename classA<T>::template innerClassA;
        // innerClassA <T, S> mult; // Not working
        typename classA<T>::innerClassA myInnerClassA; // Not working
    }
};

int main(int argc, char** argv)
{
    classB<int> obj2;
    obj2.foo();

   return 0;
}

I would like to create an object of innerClassA inside the function foo. But unfortunately, I am not able to do it. Can someone give me a hand?

Best wishes !

Aucun commentaire:

Enregistrer un commentaire