【发布时间】:2017-12-09 06:37:02
【问题描述】:
我尝试使用 Qt 声明函数模板以仅计算 quint8、quint16 和 quint32 的一些值。
我写道:
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);
但concept 和requires 关键字不会作为语法的一部分突出显示。当我尝试编译此代码时出现以下错误:
concept does not name a type
...
requires does not name a type
我第一次尝试在 Qt 中使用模板。我不明白如何修复这个错误,以及为什么编译器无法理解关键字。
在项目文件中我添加QMAKE_CXXFLAGS += -std=c++11 和CONFIG += c++11
但没有任何改变。
我不明白我应该在谷歌上问什么,所以我找不到答案......
【问题讨论】:
-
题外话:是Qt,不是QT。
标签: c++ qt templates constraints keyword