473,241 Members | 1,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

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 1876
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Piotr Sawuk | last post by:
just a quick question out of curiosity: how to initialize const arrays? struct srat { long num; ulong den; srat(){} } struct collisions
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
3
by: Mark Dunmill | last post by:
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...
1
by: bvisscher | last post by:
I posted this recently in microsoft.public.vc.language and was redirected here. I also searched this ng and found some relavant threads. The most relavent I found was: ...
6
by: Marvin Barley | last post by:
I have a class that throws exceptions in new initializer, and a static array of objects of this type. When something is wrong in initialization, CGI program crashes miserably. Debugging shows...
3
by: johnmmcparland | last post by:
Hi all, I would like to have a static constant array inside a class definition which would contain the number of days in each month (I am writing a Date class as an exercise). However my...
20
by: JohnQ | last post by:
The way I understand the startup of a C++ program is: A.) The stuff that happens before the entry point. B.) The stuff that happens between the entry point and the calling of main(). C.)...
6
by: recherche | last post by:
Hi! Is the following program valid, although it compiles and executes successfully? // params modifier // used to declare array parameter // value type, no constructor using System;
17
by: copx | last post by:
I don't know what to think of the following.. (from the dietlibc FAQ) Q: I see lots of uninitialized variables, like "static int foo;". What gives? A: "static" global variables are initialized...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.