Solved

what is the syntax of a __gc array?

Posted on 2004-08-07
10
302 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 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