Managed C++: Using __gc pointers

Posted on 2004-10-18
Last Modified: 2013-12-03
I have the following header file (well, what you need anyway)

---- code ----------------------------------------------------------------
namespace AGRPDLL
public __value struct sData {
      double Freq;                        // stores Freq for single data entry
      double Re;                              // stores Re{ RCS } for single data entry
      double Im;                              // stores Im{ RCS } for single data entry

public __gc struct sSweep {
      double Azimuth;                        // stores Azimuth angle (in degrees) for this data set
      double Elevation;                  // stores Elevation angle (in degrees) for this data set      
      // dynamic array
      sData VV __gc[];                  // managed pointer to VV set (freq, real, imaginary)
      sData HH __gc[];                  // managed pointer to HH set (freq, real, imaginary)      

public __gc struct sSCC {
      double DeltaFreq;                  // delta step of freq data
      int         numFreqs;                  // number of freqs in this range profile      
      double DeltaAngle;                  // delta step of freq data
      int         numAngles;                  // number of angels in each cut

      // dynamic array
      sSweep *FreqSweep;                              // managed pointer to azimuth/elevation set (1D)      

public __gc class AGRPreprocessor
      sSCC      *SCC;                        // structure which holds all DATA

}// end namespace AGRPDLL

The line of code  I am having trouble with is:

---- code ----------------------------------------------------------------
SCC->FreqSweep = new sSweep[SCC->numAngles];

I get the following errors (all for the same line):

----- error --------------------------------------------------------------
error C2691: 'AGRPDLL::sSweep' : invalid type for __gc array element
error C3149: 'AGRPDLL::sSweep' : illegal use of managed type 'AGRPDLL::sSweep'; did you forget a '*'?
error C2691: 'AGRPDLL::sSweep __gc *' : invalid type for __gc array element

I am guessing that the error has to do with the way I have defined the sSweep struct, or the way I have defined the FreqSweep pointer in the sSCC struct.  I have tried to define this as:

sSweep FreqSweep __gc[];

But I get an error in the header file that way.  This is way I have it defined the way I do.  If I take the line of code that is giving trouble (SCC->FreqSweep = new sSweep[SCC->numAngles];) out of the code, I get no errors and everything runs fine.  

Any ideas?  Sorry this is so long a post, I figure the more info you have the better you can understand my problem.
Question by:donfmorrison
  • 2
LVL 16

Accepted Solution

nonubik earned 75 total points
ID: 12345229
SCC->FreqSweep = new sSweep * [SCC->numAngles];

and define sSweep *FreqSweep[];

Author Comment

ID: 12347675
ok, that solved the compile issues.  Thank you very much.  That array sets up nicely now.

I have a new issue...

How do I access the members of this array now?  With the following code, I get a runtime error which indicates in debug that SCC->FreqSweep[i] is an invalid reference.  Am I doing it incorrectly?  

--- code ----------------------------------------------
//loop through each Sweep and setup arrays
for( i=0; i < SCC->numAngles; i++ ) {
      SCC->FreqSweep[i]->VV = new sData[SCC->numFreqs];
      SCC->FreqSweep[i]->HH = new sData[SCC->numFreqs];

You have been a great help! I appreciate it...

Author Comment

ID: 12349641

I got it figured out... This does the trick.  

//loop through each Sweep and setup arrays
for( i=0; i < SCC->numAngles; i++ ) {
      //instantiate each object
      SCC->FreqSweep[i] = new sSweep;

      //produce the data structure
      SCC->FreqSweep[i]->VV = new sData[SCC->numFreqs];
      SCC->FreqSweep[i]->HH = new sData[SCC->numFreqs];

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2015 compiler settings for 32bit 1 103
Courier BOLD character spacing doesn't match UNBOLD 3 83
Looking for font BAU LF Bold 3 103
Remove Office macro by VC++ 10 89
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++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

896 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

12 Experts available now in Live!

Get 1:1 Help Now