Я пытаюсь использовать
Код: Выделить всё
intКод: Выделить всё
constexprКод: Выделить всё
constexpr SymbolКод: Выделить всё
SymbolRefКод: Выделить всё
template
struct SymbolRef { };
struct Symbol {
int const id_;
consteval Symbol() : id_(1) { }
template
consteval operator SymbolRef() const
{
return SymbolRef{};
}
};
Код: Выделить всё
error: non-type template argument is not a constant expression
12 | return SymbolRef{};
| ^~~
:12:22: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
Код: Выделить всё
constevalI understand that this code is ill-formed when
Код: Выделить всё
operator SymbolRef()Код: Выделить всё
constexprКод: Выделить всё
constexprКод: Выделить всё
this->id_Why is this code illegal when using it with
Код: Выделить всё
constevalEDIT:
The following does compile with g++ - but only when using
Код: Выделить всё
this->id_Код: Выделить всё
template
struct SymbolRef { };
struct Symbol {
int const id_;
consteval Symbol() : id_(1) { }
template
consteval operator SymbolRef() const
{
return SymbolRefid_>{};
}
};
Код: Выделить всё
this->Источник: https://stackoverflow.com/questions/781 ... r-function
Мобильная версия