constexprの実体化?
昔、constexpr文字列を使ったときと同様のノリで
static constexprメンバ変数として数字配列を作成したらリンクエラーがでました
class Hoge{ public: static constexpr auto array = {1,2,3,4}; // Error static constexpr auto word = (char*)"hoge"; // OK! }; int main() { Hoge::array; Hoge::word; }
・・・はて?
調べてみると、以下のように実体化しないとダメなようです
#include <initializer_list> class Hoge{ public: static constexpr auto array = {1,2,3,4}; static constexpr auto word = (char*)"hoge"; }; constexpr std::initializer_list<const int> Hoge::array; int main () { Hoge::array; Hoge::word; }
これは、なんとも冗長な・・・
http://melpon.org/wandbox/permlink/QGrLcxRZxqLryV3j