Using type declared in template class

Hi

This code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Online C++ compiler to run C++ program online
#include <iostream>

template <typename T>
class Test
{
    public:
        using MyType = unsigned int;
    
    private:
        T t;
};

template <typename T>
void doSomething(Test<T> myTest, Test<T>::MyType mT)
{
    
}

int main() {
    // Write C++ code here
    std::cout << "Hello world!";

    return 0;
}


presents this error:

1
2
/tmp/aIhavoWVkC.cpp:15:43: error: 'Test<T>::MyType' is not a type
   15 | void doSomething(Test<T> myTest, Test<T>::MyType mT)


The code works if I refer to a particular template type (e.g. Test<string>::MyType). Is there no way to refer to a type declared in a class template (as opposed to the class instantiated from a particular template)?

Thanks
typename is required for a dependent type:
1
2
3
4
5
template <typename T>
void doSomething(Test<T> myTest, typename Test<T>::MyType mT) // Note: typename
{
    
}
thanks
Topic archived. No new replies allowed.