模板类如何在 GCC 和 Clang 中继承子类
How is template class inherited child classes in GCC and Clang
我不明白下面的代码示例中的GCC和Clang行为。为什么GCC/Clang允许调用非继承的类,如check<'d'>。
#include <iostream>
template<char TCh> struct check { static constexpr char ch = TCh; };
template<char ... TChs> struct checker
: public check<TChs>...
{};
using double_litters = checker<'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'>;
int main()
{
std::cout << double_litters::check<'d'>::ch << std::endl; // GCC/Clang compile OK, VS compile ERROR
std::cout << double_litters::check<'1'>::ch << std::endl; // GCC/Clang compile OK, VS compile OK
return 0;
}
不确定为什么会发生这种情况,以及这是否真的是一个错误。但是你可以这样修复它:
double_litters().check<'d'>::ch
这将在 GCC 中给出错误,不要检查叮当...
相关文章:
- 继承函数的重载解析
- 继承期间显示未知行为的子类
- 头文件-继承c++
- 奇怪的结构&GCC&clang(void*返回类型)
- 为什么在保护模式下继承升级不起作用
- 构造函数SFINAE和继承在clang中失败
- 继承的构造函数,在 clang++3.9 中编译,在 g++ 7 中失败
- 继承 C++14 中的模板化运算符 =:g++ 和 clang++ 的不同行为
- 模板类如何在 GCC 和 Clang 中继承子类
- 在继承多个空类时,了解GCC/Clang vs MSVC2015之间的不同填充规则
- 不能继承 clang 和 gcc 中同一类的显式模板专用化
- GCC称将功能与多个继承过载时,称其为模棱两可,但Clang和MSVC没有
- Clang:在拥有公共虚拟继承的同时,无法投放私人基础
- 继承默认构造函数在 gcc 中失败并在 clang 中工作,哪个有错误?
- clang/g++ 与私有继承和使用声明的区别
- GCC vs clang -使用' make_overload '可变lambda继承时的模糊重载
- 为什么clang和gcc在虚拟继承代码上存在分歧?
- Clang编译有效,而GCC不适用于钻石继承
- 多重继承的菱形问题:Gcc / Clang错误,但Visual Studio没有错误
- C++11 继承代码无法使用 clang 进行编译