Я пытаюсь использовать
Код: Выделить всё
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
Код: Выделить всё
consteval
I understand that this code is ill-formed when
Код: Выделить всё
operator SymbolRef()
Код: Выделить всё
constexpr
Код: Выделить всё
constexpr
Код: Выделить всё
this->id_
Why is this code illegal when using it with
Код: Выделить всё
consteval
EDIT:
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