Reputation: 43
I am trying to access a .NET structure member but compilation fails even for this simple example:
.h:
using namespace System::Drawing;
namespace MyNamespace{
public ref class MyClass{
public:
MyClass();
static const System::Drawing::Size MinimumSize = System::Drawing::Size(20,20);
}
}
.cpp:
#include "MyInclude.h"
MyClass::MyClass(){
int i = MinimumSize.Width;
// .....
}
The statement which assigns the MinimumSize.Width to the local variable i fails to compile:
The assignment compiles without error when I remove the "const" in the declaration but I want to keep the value public and read-only.
Can somebody give me a hint how to specify that?
Upvotes: 0
Views: 266
Reputation: 189
I have just tried it: 'initonly' produces two messages when I attempt to allocate MinimumSize.Width to 'i':
plus the message
I am using this solution:
int i = (( System::Drawing::Size)MinimumSize).Width;
This cast gets rid of the 'const', compiles without any error/warning and executes as expected. Or is this a bit too much brut force?
Regards PaulTheHacker
Upvotes: 1