• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:

Managed C++: Using __gc pointers

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
{
private:
      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.
0
donfmorrison
Asked:
donfmorrison
  • 2
1 Solution
 
nonubikCommented:
Try
SCC->FreqSweep = new sSweep * [SCC->numAngles];

and define sSweep *FreqSweep[];
0
 
donfmorrisonAuthor Commented:
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...
0
 
donfmorrisonAuthor Commented:
OK.

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];
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now