【发布时间】:2015-06-19 14:52:13
【问题描述】:
#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);
}
给出以下错误:(try it)。
main.cpp:13:1: error: 'a' does not name a type
a B<T>::foo(a b) {return b}
内联定义不会出现此错误。
谁能解释一下为什么在这种情况下编译器无法解析a,以及如何使这段代码工作。
我不想明确解析所有的名称
typename B<T>::a B<T>::foo(typename B<T>::a b) {return b}
因为它会降低可读性。
【问题讨论】: