Код: Выделить всё
#include
template
requires std::is_arithmetic_v && (N >= 1)
class Vector
{
static constexpr std::size_t Dimension = N;
std::array Elements;
public:
constexpr Vector() noexcept : Elements{} {}
constexpr ~Vector() = default;
static constexpr Vector ZeroVector{};
};
int main()
{
Vector boo = Vector::ZeroVector;
}
Clang выдает следующую ошибку:
Код: Выделить всё
:13:29: error: constexpr variable cannot have non-literal type 'const Vector'
13 | static constexpr Vector ZeroVector{};
| ^
:18:28: note: in instantiation of template class 'Vector' requested here
18 | Vector boo = Vector::ZeroVector;
| ^
:13:29: note: incomplete type 'const Vector' is not a literal type
13 | static constexpr Vector ZeroVector{};
| ^
:5:7: note: definition of 'Vector' is not complete until the closing '}'
5 | class Vector
| ^
1 error generated.
Compiler returned: 1
Код: Выделить всё
(13): error C2027: use of undefined type 'Vector'
(5): note: see declaration of 'Vector'
(13): note: the template instantiation context (the oldest one first) is
(18): note: see reference to class template instantiation 'Vector' being compiled
Compiler returned: 2
Код: Выделить всё
template requires std::is_arithmetic_v && (N >= 1)
const constinit Vector Vector::ZeroVector{};
Подробнее здесь: https://stackoverflow.com/questions/782 ... -constinit