c++11 - Template specialization with constexpr non POD data initialization results in linker error when used in constructor as default value -


consider this:

struct teststruct {     uint16_t m_a : 8;     uint16_t m_b : 8; };  template<typename t> struct some_trait {     constexpr static const teststruct value = {0,0}; };  template<> struct some_trait<int> {     constexpr static const teststruct value = {1,1}; };  template<class t> class obj { public:     obj(teststruct t = some_trait<t>::value) : m_t(t)     {      }      teststruct m_t; };  int main(int argc, const char * argv[]) { // linker error here -> undefined symbol some_trait<int>::value     obj<int> o;       teststruct t = some_trait<int>::value;     obj<int> o1(t); // -> works } 

the following produces linker error, complaining some_trait not defined. have 2 questions:

  1. why happening? i'm guessing has either constexpr specifier or non-pod type of teststruct ?

  2. is there way make work, while still keeping default value in constructor?

thanks!


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -