[VS2005] class variable members marked as initonly

M

marco_segurini

Hi,

The following C++ managed console application compile with no errors
or warning even if the readonly class members are not explicitly
initialized.

Is there any way to force the compiler to inform me that the readonly
class members are not explicitly initialized?

If I translate this program to C# using 'readonly' instead of
'initonly' the compiler returns me a warning for each readonly member
that is not expliciply inizialized.

TIA.
Marco.

///////////////////////////////////////////

#include "stdafx.h"

using namespace System;

ref class Hello
{
};

ref class TestInitOnly
{
public:
TestInitOnly()
{
}

initonly int i_;
initonly Hello^ h_;
};

int _tmain()
{
TestInitOnly^ init = gcnew TestInitOnly();
}
 
T

Tomas Restrepo \(MVP\)

Hi Marco,
The following C++ managed console application compile with no errors
or warning even if the readonly class members are not explicitly
initialized.

Is there any way to force the compiler to inform me that the readonly
class members are not explicitly initialized?

If I translate this program to C# using 'readonly' instead of
'initonly' the compiler returns me a warning for each readonly member
that is not expliciply inizialized.

AFAIK, there's not such a warning currently implemented, and the compiler
will initialize the field to the default value (0/nullptr). You might want
to post a feature request on the msdn feedback center for this!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top