Solved

Managed C++: Using __gc pointers

Posted on 2004-10-18
3
396 Views
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
{
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
Comment
Question by:donfmorrison
  • 2
3 Comments
 
LVL 16

Accepted Solution

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

and define sSweep *FreqSweep[];
0
 
LVL 1

Author Comment

by:donfmorrison
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...
0
 
LVL 1

Author Comment

by:donfmorrison
ID: 12349641
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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
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…
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…

809 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