在C++中它的确定有一个funcction,需要一个函数的局部类型:为什么模板不能使用函数本地类型?
int main() {
struct S { static void M(const S& s) { } };
S s;
S::M(s);
}
但不能确定,有一个模板,做:
template<typename T> void Foo(const T& t) { }
int main() {
struct S { } s;
Foo(s); // Line 5: error: no matching function for call to 'Foo(main()::S&)'
}
14.3.1 paragraph 2 in the c++ standard.
A型[...]不可用作模板类型的模板参数
为什么C++不允许这样做?
到目前为止,它是内在的类型没有关联,而这可能意味着该把他们作为一个ARG函数必须有没有联系我听过的最好说明。但没有理由我可以看到模板实例化必须有联系。
p.s.请不要只是说“thats not allowed because the standard says it's not”
没有什么好的理由,C++ 0x将删除这个限制(但不是在p.s链接的那个限制;我仍然不知道为什么不允许)。 – 2010-08-12 17:21:05
@Mike;简明扼要! – BCS 2010-08-12 17:22:10