Consider the following snippet:
extern "C" {
#include "POD.h" // Defines struct POD;
}
template<class Base>
struct non_copyable : Base
{
non_copyable() {}
private:
non_copyable(non_copyable const&);
non_copyable& operator=(non_copyable const&);
};
class wrapper : non_copyable<POD>
{
typedef non_copyable<POD> _base_t;
public:
wrapper() : _base_t()
{}
};
My attempt is to make sure that the base-class subobject POD
is zero-initialized in all cases in C++03, C++11 and C++14, when creating local or temporary objects, static variables, by any of the syntactic flavours of new-expressions, etc. Also, I want to implement that in the simplest/shortest way as possible.
I believe that with the _base_t()
initialization in wrapper
's initializer-list I'm done, but I'm not fully sure if, since non_copyable
has a user-defined default constructor, if initialization rules will be propagated from wrapper
to POD
, and thus, since I'm not explicity calling Base()
in non_copyable
's initializer-list, if it will be zero-initialized through the wrapper
constructor in a standard conforming manner.
Also, I cannot use = default
for the non-copyable
's default constructor since wrapper
must compile in C++03
, so a user-defined constructor is mandatory here.
Some guidance in that? I'm a bit confused about the mess of initialization rules (which is a real thing: Default, value and zero initialization mess).