Vah*_*agn 9 c++ inheritance templates specialization language-lawyer
考虑以下代码:
#include <type_traits>
template < typename > struct BB { };
template < > struct BB<float> : BB<int> { };
struct DD : BB<float> { };
template < typename... Args >
void ff(BB<Args...>) { }
int main()
{
ff(BB<float>{});
ff(DD{}); // FAILS! 'BB<Args ...>' is an ambiguous base class of 'DD'
return 0;
}
Run Code Online (Sandbox Code Playgroud)
调用调用ff(DD{})无法编译,因为gcc-8.3不想从BB<float>和中选择一个BB<int>(clang执行相同操作)。但是BB<float> isa BB<int>,为什么BB<float>不可以选择?
问题是:这是否符合标准?在定义ff或BB帮助gcc-8.3选择时是否有解决方法BB<float>?
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |