468,766 Members | 1,523 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,766 developers. It's quick & easy.

Static String Array Initialization in MC++

Hi, I want to initialize a static String array in MC++. What I want to
do is to initialize my String array like the C# way: new String[]
{"11", "22"} but I could not find an equivalent in MC++. The onlu
thing I can do is this: new String*[2] but I cannot specified any
initial values... Did someone have any ideas???

Here is an example of what I want to do:
C#
struct TestingStruct
{
public String a;
public String[] b;

public TestingStruct( String aa, String[] bb )
{
a = aa;
b = bb;
}
};

TestingStruct[] Test1 =
{ new TestingStruct("abc", new String[] {"11", "22"}),
new TestingStruct("def", new String[] {"33", "44"})
};

MC++
__gc struct TestingStruct
{
String* a;
String* b[];

TestingStruct( String* aa, String* bb[] )
{
a = aa;
b = bb;
}
};

static TestingStruct* Test1[] =
{ new TestingStruct("AF", new String*[2]), // This is working but
how can I add initial values???
new TestingStruct("BC", new String*[2]) // This is working but
how can I add initial values???
};

Any help will be appreciated...

Remi

Nov 17 '05 #1
2 1703
Hi !

The answer is simple: you can't. Here's an exerpt from the C/C++ Library
Reference on MSDN:'

"Provides a value for the initialized object. Initializers cannot be
specified for arrays. The new operator will create arrays of objects only if
the class has a default constructor."

The code you posted cannot be used in the way you describe. Instead, create
a static function that takes the struct count, the string count and an array
of strings, then initializes the strings by using a for-loop. The function
returns a pointer to the first struct, and through a parameter it returns
the amount of structures actually initialized.

-Antti Keskinen
<rm******@cae.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi, I want to initialize a static String array in MC++. What I want to
do is to initialize my String array like the C# way: new String[]
{"11", "22"} but I could not find an equivalent in MC++. The onlu
thing I can do is this: new String*[2] but I cannot specified any
initial values... Did someone have any ideas???

Here is an example of what I want to do:
C#
struct TestingStruct
{
public String a;
public String[] b;

public TestingStruct( String aa, String[] bb )
{
a = aa;
b = bb;
}
};

TestingStruct[] Test1 =
{ new TestingStruct("abc", new String[] {"11", "22"}),
new TestingStruct("def", new String[] {"33", "44"})
};

MC++
__gc struct TestingStruct
{
String* a;
String* b[];

TestingStruct( String* aa, String* bb[] )
{
a = aa;
b = bb;
}
};

static TestingStruct* Test1[] =
{ new TestingStruct("AF", new String*[2]), // This is working but
how can I add initial values???
new TestingStruct("BC", new String*[2]) // This is working but
how can I add initial values???
};

Any help will be appreciated...

Remi

Nov 17 '05 #2
rm******@cae.com wrote:
Hi, I want to initialize a static String array in MC++. What I want to
do is to initialize my String array like the C# way: new String[]
{"11", "22"} but I could not find an equivalent in MC++. The onlu
thing I can do is this: new String*[2] but I cannot specified any
initial values... Did someone have any ideas???


In C++/CLI you can do it now. Of course you have two choices: either use
Beta product, or don't initialize arrays. The VC++ 2003 form designer
can't initialize arrays either, but VC++ 2005 can and does.

Tom
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Piotr Sawuk | last post: by
8 posts views Thread by Peter B. Steiger | last post: by
3 posts views Thread by Mark Dunmill | last post: by
20 posts views Thread by JohnQ | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.