Wednesday, 15 April 2015

c++ - c++11 plain old object default value -



c++ - c++11 plain old object default value -

how can initialize fellow member variable of pod (plain old data) in c++11?

class { public: int theanswer; // not initialized }; static_assert(std::is_pod<a>::value, "a must plain old object"); class b { public: int theanswer { 42 }; // should initialize 42 }; static_assert(std::is_pod<b>::value, "b must plain old object"); // error class c { public: c() : theanswer { 42 } { } // obviously, not trivial default constructor, not work int theanswer; }; static_assert(std::is_pod<c>::value, "c must plain old object"); // error

you initialize whole object. plain old info object that: plain old data, no invariants, initialization, or of fancy stuff. if want initialization, it's not pod.

but maybe don't need pod. maybe trivially copyable enough? if want memcpy between objects, trivially copyable trait you're looking for, not pod.

c++ c++11 initialization

No comments:

Post a Comment