Re: [PATCH kvm-unit-tests 2/4] Introduce a C++ wrapper for the kvm APIs

Michael S. Tsirkin
2010-11-28T22:29:10Z

On Sun, Nov 28, 2010 at 04:04:34PM -0600, Anthony Liguori wrote:
> >To create an object on the stack, you must have the class definition in
> >a public header and a public constructor/destructor.
> >This is exactly the same in C.
>
> It's really more of a design statement than a statement about C++ vs. C.
>
> In qdev today, we mix object initialization with a user-exposed
> factory. This means that you cannot do something simple like:
>
> struct i440fx {
> struct piix3 piix;
> };
>
> void i440fx_init(struct i440fx_init *obj) {
> piix3_init(&obj->piix);
> }
>
> But rather need to use ugly factory functions with all sorts of
> DO_UPCAST. This is really unfriendly especially for writing test
> cases.

Yes, I agree. Just moving memory allocation out of there
will fix most of the ugliness.

--
MST