在 GCC 中,这段代码无法编译,因为 T 被隐藏,但是在 VS2005 中,它编译时没有警告,那么 VS 编译器做了什么假设?
template<typename T>
class Foo
{
template<typename T>
void Bar(const T& bar)
{
...
}
};
经过 3 个月的搜索后找到了正确的答案:) 就在14.6.1/4
标准的:
模板参数不得在其范围内(包括嵌套范围)重新声明。模板参数不得与模板名称同名。
Example:
template<class T, int i> class Y {
int T;
// error: template-parameter redeclared
void f() {
char T;
// error: template-parameter redeclared
}
};
template<class X> class X; // error: template-parameter redeclared
如果 Microsoft 编译器让它编译时没有错误甚至警告,那么它就不符合要求。我不知道是什么驱使它让它不呻吟。您可以尝试提高警告级别。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)