How to initialize a String^ *

80 views Asked by At

I'm using VS2010, a Visual C++ project.

I've declared my var to store some options to be shown in a control:

System::String^ * operaciones;

Now, in my void InitializeComponent(void), I'm trying to load to this var the options I want to load later. I tried several ways and no one could even compile.

I've:

operaciones = {  "Umbralizado" ,
                 "ROI"  ,
                 "Contornos" ,
                 "DFT" ,
                 "R - V"};

Which seems fine (to me) in order to fill the String^ *. However, I'm getting:

Error   2   error C2059: error de sintaxis : '{'    c:\...\Form1.h  98
Error   3   error C2143: error de sintaxis : falta ';' delante de '{'   c:\...\Form1.h  98

Translated messages:

Syntax error: '{'
A ';' is missing before '{'

If I comment the initialization, my program compiles fine, so it's not because I missed a { nor ; before it.

I've looked for C2059 and C2143 errors, but I still can't find out what am I doing wrong. I think it's like "can't see the forest for its trees", it can't be so difficult to do it.

EDIT: I've changed it to managed array, but I'm still getting the same errors. I've cleaned and then build again with VS, but nothing new happened:

enter image description here

1

There are 1 answers

2
Hans Passant On BEST ANSWER

You cannot get this going, it is illegal to store managed objects in an unmanaged array. Or to reference them with an unmanaged pointer. The garbage collector can never correctly find the objects back, it must be a managed array. The compiler will not produce a decent error message to help you discover this basic fact.

Proper syntax is:

   array<String^>^ operations = { "foo", "bar", "baz" };