Your Color
member should probably be of some ColorType
type. And classes Green
and Blue
should be derived from ColorType
.
Please see rbaghbanli's code which does exactly this (accepted answer).
Then you can put all aspects shared by classes Green and Blue into ColorType, which is quite useful.
If you user a void*
or boost::any
there is nothing you can really do with this pointer, as C++ forgets what it is actually pointing to.
Background: C++ is completely statically typed and does not allow introspection. The only available runtime mechanism is virtual functions, and this mechanism is quite limited.
If you really need something which can be any type, you have to write it yourself. But I assume you do not really need this. I assume you need Can be any of a kind.
and this is well enough supported in C++ through derivation.