I have some global constexpr Masks that I would like to make a part of my Mask class as a static constexpr to reduce globals in main.cpp
Currently this works:
main.cpp has:
constexpr Mask cg_completeMask(0xffffffffffffffffull, 0x1ffff);Mask.hpp has (reduced for SO):
class Mask { unsigned long long m_64; unsigned int m_32; public: constexpr Mask(const unsigned long long ac_64, const unsigned int ac_32) : m_64(ac_64), m_32(ac_32) {} };
What I tried to move the global Masks from main.cpp:
Mask.hpp has:
class Mask { unsigned long long m_64; unsigned int m_32; public: static constexpr Mask completeMask; constexpr Mask(const unsigned long long ac_64, const unsigned int ac_32) : m_64(ac_64), m_32(ac_32) {} };Mask.cpp has:
constexpr Mask Mask::completeMask(0xffffffffffffffffull, 0x1ffff);
What I tried produces these errors:
In file included from main.cpp:3:0: Mask.hpp:12:27: error: constexpr static data member 'completeMask' must have an initializer static constexpr Mask completeMask; ^ In file included from Mask.cpp:1:0: Mask.hpp:12:27: error: constexpr static data member 'completeMask' must have an initializer static constexpr Mask completeMask; ^
static constexprmember that is not a function memberMaskinsideclass Maskthat is your first problem.Maskcontains aMask. Try to write down the contents of aMaskobject on paper. Stop when you reach the end of the page, to save trees. It never ends!