#include <iostream>
template<class T> struct A {
typedef T a;
};
template<class T>
struct B {
typedef typename A<T>::a a;
static a foo(a b);
};
template<class T>
a B<T>::foo(a b) {return b}
int main() {
std::cout << B<int>::foo(1);
}
Gives the following error: (try it).
main.cpp:13:1: error: 'a' does not name a type
a B<T>::foo(a b) {return b}
An inline definition does not suffer from this error.
Could someone please explain why the compiler can not resolve a
in this case, andhow I can make this code work.
I would like to not resolve all the names explicitly like
typename B<T>::a B<T>::foo(typename B<T>::a b) {return b}
As it would decrease readability.