【问题标题】:Qt C++ using constraints in function templatesQt C++ 在函数模板中使用约束
【发布时间】:2017-12-09 06:37:02
【问题描述】:

我尝试使用 Qt 声明函数模板以仅计算 quint8quint16quint32 的一些值。 我写道:

template<typename T>
concept CrcCompatible = typeid(T) == typeid(quint8) || typeid(T) == typeid(quint16) || typeid(T) == typeid(quint32);

template<typename T> requires CrcCompatible<T>
T crc(T initial, T polynomial, T *pcBlock, T len, bool isFinalXor);

conceptrequires 关键字不会作为语法的一部分突出显示。当我尝试编译此代码时出现以下错误:

concept does not name a type
...
requires does not name a type

我第一次尝试在 Qt 中使用模板。我不明白如何修复这个错误,以及为什么编译器无法理解关键字。

在项目文件中我添加QMAKE_CXXFLAGS += -std=c++11CONFIG += c++11 但没有任何改变。

我不明白我应该在谷歌上问什么,所以我找不到答案......

【问题讨论】:

  • 题外话:是Qt,不是QT。

标签: c++ qt templates constraints keyword


【解决方案1】:

我想问题是 C++11 不支持概念。从我在documentation 中可以看到,这些概念只会是available in C++20。无论如何,如果现在某些编译器支持,您应该通过--std=c++11以外的其他标志启用此支持。

【讨论】:

  • 我真的很粗心
猜你喜欢
  • 2021-11-18
  • 2022-09-29
  • 2021-09-04
  • 1970-01-01
  • 2021-08-29
  • 2021-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多