Solved

what is the syntax of a __gc array?

Posted on 2004-08-07
10
299 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
 
LVL 55

Expert Comment

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

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now