template-specialization - 为什么概念类模板特化会导致错误
问题描述
我尝试使用 gcc 10 构建以下内容-std=gnu++20 -fconcepts
:
template <std::signed_integral T>
class MyClass{ T a; };
template <std::unsigned_integral T>
class MyClass{ T a; };
为什么这段代码会导致以下错误?
> declaration of template parameter ‘class T’ with different constraints
> 55 | template <std::unsigned_integral T>
> | ^~~
不应该没问题吗?
解决方案
不应该没问题吗?
不,约束不会使类“可重载”。您仍然需要一个主模板,然后您需要专门化该模板:
template <std::integral T>
class MyClass;
template <std::signed_integral T>
class MyClass<T>{ T a; };
template <std::unsigned_integral T>
class MyClass<T>{ T a; };
推荐阅读
- visual-studio-code - 如何将 Windows 终端 (UWP) 设置为 Visual Studio Code 的外部终端?
- c# - FromHeaderAttribute 不适用于属性
- osgi-bundle - 使用 JBoss Fuse Fabric 发布和访问 OSGI 服务
- javascript - 在 zeit-now 上通过 express 应用程序使用链接到 html 的 CSS 和 JS 客户端文件
- github-api - 您如何通过 github 应用从上游存储库获取通知?
- android - 使用加速度计了解手机的运动速度并做出反应(Android Studio)
- sql - 使用 uniq ID 对日期范围和岛屿进行分组,而无需按分隔符进行分区
- documentation - 我想做文档查看器
- mysql - 如何根据 R Mysql DB 中的时间戳删除表?
- android - 无法使用 Retrofit 2.6.1 成功发送 POST 请求 - JSON 转换器的问题