neu*_*est 7 c++ templates nested multiple-inheritance visual-studio-2013
Visual Studio 2013(更新2)在编译模板函数时抛出编译时错误,该模板函数的返回类型是嵌套类型名称,已通过多重继承隐藏,并使用using关键字再次显示; 如下面的代码所示:
struct Base1
{
typedef int value_type;
};
struct Base2
{
typedef double value_type;
};
struct Derived : Base1, Base2
{
using Base1::value_type;
};
template<typename T>
typename T::value_type nullary_function() { return 0; }
template<typename T>
typename T::value_type unary_function(T t) { return 0; }
int main()
{
nullary_function<Derived>(); // Error: C2770
unary_function( Derived() ); // Error: C2893
return 0;
}
Run Code Online (Sandbox Code Playgroud)
(错误编号取决于函数是否接受模板参数,如注释中所示.)
G ++ 4.7接受此代码.
具体来说,我想知道C++标准在这个问题上有什么说法,以及这是否是VC++编译器错误.(在我看来,using在我知道的情况下,使用关键字使嵌套类型可见,使其在其他所有情况下都可见.
我也知道using关键字的行可能会改变
using Base1::value_type;
Run Code Online (Sandbox Code Playgroud)
至
typedef Base1::value_type value_type;
Run Code Online (Sandbox Code Playgroud)
为了使代码能够正确编译和运行,但是对于某些(可能)有效的代码在某些编译器而不是其他编译器上进行编译而言,可移植性似乎不好 - 因此需要澄清.
| 归档时间: |
|
| 查看次数: |
179 次 |
| 最近记录: |