我有:
constexpr bool is_concurrency_selected()const
{
return ConcurrentGBx->isChecked();//GBx is a groupbox with checkbox
}
我收到错误:
C:\...\Options_Dialog.hpp:129: error: enclosing class of 'bool Options_Dialog::is_concurrency_selected() const' is not a literal type
有什么想法吗?
这意味着你的类不是文字类型...这个程序是无效的,因为Options
不是文字类类型。但Checker
是文字类型。
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();
}
叮当印记
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 {
如果你解决这个问题并做出Options
构造函数constexpr
,我的示例代码片段已编译。类似的事情可能适用于您的代码。
你似乎不明白什么constexpr
方法。我建议阅读一本关于它的书(如果已经存在这样的书的话)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)