<分区>
我在 Wiki 上查找关键字 typename ( http://en.wikipedia.org/wiki/Typename ),它给出了一个示例,在 T::bar 之前需要 typename
template <typename T>
void foo(const T& t)
{
// declares a pointer to an object of type T::bar
T::bar * p;
}
struct StructWithBarAsType {
typedef int bar;
};
int main() {
StructWithBarAsType x;
foo(x);
}
为什么 C++ 在为 foo(x) 生成代码时不检查 StructWithBarAsType 并发现 T::bar 实际上是一个类型?是不可以还是只是效率的考虑?