c++ - How to initialize a union of pointers to nullptr? -
assume have c++ class this:
class container { private: union { foo* foo; bar* bar; } mptr; };
this class constructed on stack. i.e. won't new
ed, can't declare zeroing operator new
.
can use initializer in constructor set mptr
nullptr
somehow?
container() : mptr(nullptr) { }
does not compile. not adding dummy union
member of type nullptr_t
.
container() : mptr.foo(nullptr) { }
doesn't compile, either.
use aggregate initialization, example:
container() : mptr { nullptr } { }
i don't posting links, here run through of technique.
Comments
Post a Comment