?
Solved

what is the syntax of a __gc array?

Posted on 2004-08-07
10
Medium Priority
?
307 Views
Last Modified: 2010-04-24
I declare an array in .h file as the following:
 public __gc class myClass
 {
 public:
  int myIntArray __gc[];
。。。

in the class constructor:

myIntArray= __gc new int[5];
for (int i=0;i<2;i++) myIntArray[i]=i;

what I get are compiler errors, as follows:

Lib2.cpp(22) : error C2726: “__gc new”can not create __gc object
Lib2.cpp(22) : error C2440: “=” ....

What is the proper syntax?
Thanks!  
0
Comment
Question by:CFree
  • 4
  • 3
8 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11743075
Hi CFree,

Just use

public __gc class myClass
 {
 public:
  int myIntArray *__gc;
   // etcetera
}

don't forget to delete your array in the destructor

Good luck,
Jaime.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11744267
Not solved your problem?
0
 

Author Comment

by:CFree
ID: 11745738
hi Jaime,
since the array declared as the managed code, why need i delete it in the destructor?
Thanks!
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11746441
In that case, please forget my last line, but my first suggestion is correct.
0
 

Author Comment

by:CFree
ID: 11746595
replaced wtih  int myIntArray *__gc;
the complier gives me the following errors:
e:\CurrentProj\GE\Lib2\Lib2\Lib2.h(26) : error C2143:syntax error....
e:\CurrentProj\GE\Lib2\Lib2\Lib2.h(26) : error C3150:
e:\CurrentProj\GE\Lib2\Lib2\Lib2.h(26) : error C2059:
e:\CurrentProj\GE\Lib2\Lib2\Lib2.h(26) : error C2238:
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11746619
Is your myIntArray class being reconized at that point?
Maybe you have not #included proper header.
0
 

Author Comment

by:CFree
ID: 11749393
public:
  int myIntArray *__gc;

I replaced  " int myIntArray __gc[] " with the above section  in the head file.
0
 
LVL 19

Accepted Solution

by:
drichards earned 200 total points
ID: 11757406
Correct syntax is:

    public __gc class myClass
   {
      public:
      int myIntArray __gc[];
    };


then:

    myIntArray= new int __gc[5];
    for (int i=0;i<2;i++) myIntArray[i]=i;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question