Solved

what is the syntax of a __gc array?

Posted on 2004-08-07
10
300 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
10 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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 50 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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