I have an header file, for which I want to write the definition of the function not right after the declaration. The only problem is that the return type of such function is defined thought `using`, and when I try to compile my code I got a compiler error. I've spent lots of time trying to understand what's the problem. Let me give a minimal reproducible example in order to clarify this:
and the following is the **main.cpp** file, where I simply invoke the function:
1 2 3 4 5 6 7 8
#include "foo.hpp"
int main(){
Foo<int> my_obj(96);
Foo<int>::pairtype p = my_obj.Bar();
return 0;
}
Running this with g++ -o foo -Wall -Wextra -std=c++14 foo.cpp gives the following error.
> ./foo.hpp:21:1: error: missing 'typename' prior to
> dependent type
> name 'Foo<T>::pairtype' Foo<T>::pairtype Foo<T>::Bar(){ ^~~~~~~~~~~~~~~~ typename
Now to my question: I've seen that if I put, as suggested, `typename`, then it works. However, I don't understand why it doesn't work with the `class` keyword
Now to my question: I've seen that if I put, as suggested, `typename`, then it works. However, I don't understand why it doesn't work with the `class` keyword
You're required to write typename by fiat. There is no fundamental reason that disambiguation is necessary in this case.