I run into trouble while initializing a class with constants:
Why the initialisation with a pointer to a member in the same class results into an error? The error comes up without using the class "Use"!
class A
{
private:
int a;
const int* const aptr;
public:
constexpr A( int _a):
a(_a)
, aptr( &a) // why aptr could not be initialized?
{}
};
class Data { } d1;
class B
{
private:
Data* dptr1;
public:
constexpr B(Data* _p): dptr1( _p) {}
};
class Use
{
static constexpr A a{2}; // fail! error: field initializer is not constant
static constexpr B b{&d1}; // works
};
aptris being constructed,ahas already been constructed and has a valid address.AandBoutisde ofUsewith g++, you getsorry, unimplemented: use of the value of the object being constructed in a constant expression.Ahas finished. Maybe you wantconstexpr A(int& _a)?