考虑这段代码:
template<typename T>
struct Foo
{
typedef T t_type;
};
template<typename T>
struct Bar
{
typedef T t_type;
};
template<typename U>
auto f() -> typename U::t_type::t_type
{
return typename U::t_type::t_type();
}
int main(int, char**)
{
typedef Foo<Bar<int>> Baz;
f<Baz>();
}
它不能在 VS2012 下编译:
'U::t_type::{ctor} f(void)' 的显式模板参数无效
看起来,编译器得出的结论是,第二个t_type
是typename U::t_type::t_type
命名构造函数而不是同名嵌套类型。我能做些什么来帮助澄清情况吗?