Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

Static String Array Initialization in MC++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rmathieu@cae.com - 24 May 2005 15:34 GMT
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
Antti Keskinen - 25 May 2005 05:55 GMT
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

> 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[]
[quoted text clipped - 44 lines]
>
> Remi
Tamas Demjen - 25 May 2005 19:15 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.