Link to home
Start Free TrialLog in
Avatar of donfmorrison
donfmorrison

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of nonubik
nonubik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of donfmorrison
donfmorrison

ASKER

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...
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];
}