473,394 Members | 1,812 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,394 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 1885
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.