本文介绍了constexpr和bizzare错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
constexpr bool is_concurrency_selected()const
{
return ConcurrentGBx->isChecked();//GBx is a groupbox with checkbox
}
'm getting error:
and I'm getting error:
C:\...\Options_Dialog.hpp:129: error: enclosing class of 'bool Options_Dialog::is_concurrency_selected() const' is not a literal type
p>
推荐答案
这意味着你的类不是文字类型...这个程序是无效的,因为 code>不是字面类类型。但
Checker
是一个文字类型。
It means your class is not a literal type... This program is invalid, because Options
is not a literal class type. But Checker
is a literal type.
struct Checker {
constexpr bool isChecked() {
return false;
}
};
struct Options {
Options(Checker *ConcurrentGBx)
:ConcurrentGBx(ConcurrentGBx)
{ }
constexpr bool is_concurrency_selected()const
{
//GBx is a groupbox with checkbox
return ConcurrentGBx->isChecked();
}
Checker *ConcurrentGBx;
};
int main() {
static Checker c;
constexpr Options o(&c);
constexpr bool x = o.is_concurrency_selected();
}
Clang列印
test.cpp:12:18: error: non-literal type 'Options' cannot have constexpr members
constexpr bool is_concurrency_selected()const
^
test.cpp:7:8: note: 'Options' is not literal because it is not an aggregate and has no constexpr constructors other than copy or move constructors
struct Options {
如果你解决这个问题,并使选项
构造函数 constexpr
,我的示例代码片段编译。类似的事情可能适用于您的代码。
If you fix this and make the Options
constructor constexpr
, my example snippet compiles. Similar things may apply to your code.
您似乎不明白 constexpr
是什么意思。我建议读一本关于它的书(如果这样的书已经存在,反正)。
You appear to not understand what constexpr
means. I recommend reading a book about it (if such a book exists already, anyway).
这篇关于constexpr和bizzare错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!