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 newed, 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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -