Re: deriving from a C struct
On May 23, 6:11 am, Mosfet <anonym...@free.fr> wrote:
Hi,
I would like more info about deriving from an existing C struct.
Let's say I am fed up with always writing the same code shown below :
MYSTRUCT foo;
memset( &foo, 0, sizeof(MYSTRUCT) );
A good start would be to write better code:
MYSTRUCT foo = { 0 };
instead of the above 2 lines.
foo.cbSize = sizeof(MYSTRUCT);
foo.cbSize = sizeof foo;
SendMessage(xxx, WM_MYSTRUTC, &(foo), 0);
Why the superfluous brackets?
So I would like to do something like
struct MYSTRUCT_Helper : public MYSTRUCT
{
MYSTRUCT_Helper()
{
memset( this, 0, sizeof(MYSTRUCT) );
I suspect this line would cause trouble, luckily it
is not necessary!
this->foo.cbSize = sizeof(MYSTRUCT);
what is 'foo' here?
}
}
Indenting is your friend...
and after
MYSTRUCT_Helper betterFoo;
SendMessage(xxx, WM_MYSTRUTC, &(betterFoo), 0);
Can I do something like that ?
Try this, assuming you can't change the definition
of MYSTRUCT:
struct MYSTRUCT_Helper : public MYSTRUCT
{
MYSTRUCT_Helper(): MYSTRUCT()
{
cbSize = sizeof(MYSTRUCT);
}
MYSTRUCT * operator&() { return this; }
};