G
Guest
I can't create a Constant/Read-only array field in managed C++ classes -
doesn't allow the keyword const pointer to const object on array fields in
managed C++ classes. e.g. Want to define a read/only field for an empty array
(so all the empty arrays of the given type can use the same object) however
because the pointer in the field cannot be marked as constant then it is
possible that any external party can alter this pointer to reference a new
object.
public __gc class ExampleClass
{
public:
ExampleClass();
// NOT a static read-only field - anyone can assign a new value to this
field
// e.g. ExampleClass::EmptyObjsArray = NULL
static MyObj * EmptyObjsArray __gc []; // can't add const to any part of
the declaration to make the field read-only
}
Does anyone know how to do this in C++? I know you can easily do the same
thing in C#. The problem is only with managed arrays. Can easily create
static read-only fields if the type is NOT an array. e.g.
public __gc class ExampleClass2
{
public:
ExampleClass2();
static MyObj * const OneObj = new MyObj();
};
Any ideas?
doesn't allow the keyword const pointer to const object on array fields in
managed C++ classes. e.g. Want to define a read/only field for an empty array
(so all the empty arrays of the given type can use the same object) however
because the pointer in the field cannot be marked as constant then it is
possible that any external party can alter this pointer to reference a new
object.
public __gc class ExampleClass
{
public:
ExampleClass();
// NOT a static read-only field - anyone can assign a new value to this
field
// e.g. ExampleClass::EmptyObjsArray = NULL
static MyObj * EmptyObjsArray __gc []; // can't add const to any part of
the declaration to make the field read-only
}
Does anyone know how to do this in C++? I know you can easily do the same
thing in C#. The problem is only with managed arrays. Can easily create
static read-only fields if the type is NOT an array. e.g.
public __gc class ExampleClass2
{
public:
ExampleClass2();
static MyObj * const OneObj = new MyObj();
};
Any ideas?