473,587 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1897
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.c om> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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.co m 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
3007
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
3671
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 static; if the input file contained more than entries, tough. This time I want to do it right - use a dynamic array that increases in size with...
3
5498
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 read/only field for an empty array (so all the empty arrays of the given type can use the same object) however because the pointer in the field cannot be...
1
2225
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
3547
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 uncaught exception. How to catch an exception that happened before main() try { ... } catch (...) { ... } block? Is there a way?
3
20849
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 attempts so far have been unsuccessful. Take this Test class as an example // test.hpp
20
6078
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.) main(). So, if the above is OK, does static initialization occur during A or B? What happens during A?
6
1524
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
4422
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 to 0. ANSI C guarantees that. Technically speaking, static variables go into the .bss ELF segment, while "static int foo=0" goes into .data. ...
0
8206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.