3
나는 데 왜에constexpr 및 희한 오류
C:\...\Options_Dialog.hpp:129: error: enclosing class of 'bool Options_Dialog::is_concurrency_selected() const' is not a literal type
어떤 생각을?
나는 데 왜에constexpr 및 희한 오류
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
. 나는 그것에 관한 책을 읽는 것을 추천한다 (그러한 책이 이미 존재한다면, 어쨌든).
'return ConcurrentGBx-> isChecked()'도 역시 constexpr입니까? 무슨 운영 체제에서 어떤 컴파일러? – RedX
함수 뒤에 const를 추가하는 이유는 무엇입니까? 이미 constexpr입니다. – TimKouters