On Mon, Aug 4, 2008 at 11:46 AM, thides <[EMAIL PROTECTED]> wrote:
> --- In [email protected], "Brett McCoy" <[EMAIL PROTECTED]> wrote:
>>
>> A bug was found in some C++ code recently, in my company. This code is
>> used on server software for when we have MX lookups for sending mail.
>> It was found by a customer (*yikes*) after they had applied a Sun
>> recommended patched cluster on their Solaris server:
>>
>> if (resState == NULL) {
>>     resState = new __res_state; //__res_state is a struct
> *snip*
>
> I thought new and structs were not to be used together. I have Googled
> the question and in C# there is a member function called new in a
> struct class but that is not using the keyword "new" and assigning a
> struct. It's also OT here as we are discussing C/C++. Am I wrong about
> new and struct or is that the point of the message?

For simple structs, you can use new (it will use a 'default'
constructor if one is not provided). In C++, structs are like classes
except structs default to public access whereas classes default to
private access.

In this particular case, the __res_state is *not* a simple struct and
a compiler-created default destructor does not work because
__res_state is a more complex data structure and needs better
initialization. It has nested structs with pointers, for instance.

-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
 If I were to divulge it, it would overturn the world."
 -- Jelaleddin Rumi

Reply via email to