c++ - running into trouble with constexpr -


i run trouble while initializing class constants:

why initialisation pointer member in same class results error? error comes without using class "use"!

class {        private:         int a;         const int* const aptr;      public:         constexpr a( int _a):             a(_a)            , aptr( &a)           // why aptr not initialized?      {}   };    class data { } d1;   class b {        private:         data* dptr1;      public:         constexpr b(data* _p): dptr1( _p) {}  };    class use  {        static constexpr a{2};   // fail! error: field initializer not constant     static constexpr b b{&d1}; // works };   

the code valid, , clang accepts it; seems g++ bug. address of use::a.a address constant expression, since evaluates address of object static storage duration, can used initialize constexpr object.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -