From: Tony C. on


Hi,

I have traced my problem to the following line of code which seems
to be causing a stack overflow problem: (see below)

I'm declaring a multidimenstional array of CGridbox Objcts

A CGridbox consists of 2 arrays of CApect Objects..

The code works fine when line is commented out. and breaks when put
back in...

It appears that the object has problems upon creation....

the header file for the delcaration looks like:

==Any ideas what I'm doing wrong???

Thanks very much in advance....

Tony C.

================================================
//CLASS ASPECTGRID = A DIALOG = "ASPECTGRID.H"
#pragma once
#include "CalcedChart.h"
#include "GridBox.h"
#include "Aspects.h"


// cAspectGrid dialog




class cAspectGrid : public CDialog
{
DECLARE_DYNAMIC(cAspectGrid)


public:
cAspectGrid(CWnd* pParent = NULL); // standard constructor
virtual ~cAspectGrid();

//***********************************************************
CGridBox AspGrid[17][17]; //<<<==============PROBLEM LINE **
//***********************************************************

==================================================
//CLASS GRIDBOX
#pragma once
#include "Aspect.h"

// CGridBox

class CGridBox
{


public:
CGridBox();
virtual ~CGridBox();
//Public colDeclAsp As New CAspectCollection
CAspect arrRegAsp[4];
CAspect arrDecAsp[4];

protected:

};
==================================================
//CLASS ASPECT
#pragma once


// CAspect

class CAspect
{


public:
CAspect();
virtual ~CAspect();
CPlanet P1 , P2 ;
double dbDegr1, dbDiff;
CString strAspect1;
CStringW chGlyph1;
COleDateTime dtExact, dtCalc, dtStart, dtEnd;
int intSubType; // 1 = raw2raw 2 = ra2ra 3 = raw2ra 4= ra2raw
int intAspNo; // conj thru opp + parallel and contraparallel
CAspect& CAspect::operator=(const CAspect &A);





protected:

};


==================================================
From: Tony C. on
Ok

I changed the 2 inner arrays inside the CGridbox object.

Instead of being arrays of CAspect, I changed them to

arrays of type int...and I get no stack overflow errors and

the dialog comes up just fine...



==> So when I have an array of objects inside another type
of object, do I need to somehow dynamically allocate memory
for the array of inner obects?

Some special kind of constructor for the inner ojects of type
CAspect in my case?


thanks.


From: Hector Santos on
You can try to dynamically allocate it in the constructor and
deallocate it in the destructor:

class cAspectGrid : public CDialog
{
....
public:
CGridBox *pAspGrid; // make this pointer
....
}

// CONSTRUCTOR
cAspectGrid::cAspectGrid
{
pAspGrid = new CGridBox[17*17];
}

// DESTRUCTOR
cAspectGrid::~cAspectGrid
{
delete pAspGrid;
}

Now, if you want to get a ROW and COLUMN view of the 17*17, use this
"GET" function:

CGridBox * cAspectGrid::GridBox(int row, int col)
{
// assuming base 0 for row and col
// add maybe ROW and COL checking
return pAspGrid[row*17+col];
}


Now you can use it like so:

GridBox(2,5)->Whatever

--
HLS


Tony C. wrote:

> Ok
>
> I changed the 2 inner arrays inside the CGridbox object.
>
> Instead of being arrays of CAspect, I changed them to
>
> arrays of type int...and I get no stack overflow errors and
>
> the dialog comes up just fine...
>
>
>
> ==> So when I have an array of objects inside another type
> of object, do I need to somehow dynamically allocate memory
> for the array of inner obects?
>
> Some special kind of constructor for the inner ojects of type
> CAspect in my case?
>
>
> thanks.
>
>

From: Oliver Regenfelder on
Hello,

Tony C. wrote:
> Ok
>
> I changed the 2 inner arrays inside the CGridbox object.
>
> Instead of being arrays of CAspect, I changed them to
>
> arrays of type int...and I get no stack overflow errors and
>
> the dialog comes up just fine...
>
>
>
> ==> So when I have an array of objects inside another type
> of object, do I need to somehow dynamically allocate memory
> for the array of inner obects?

No.

> Some special kind of constructor for the inner ojects of type
> CAspect in my case?

Normally not. Could you post at least the Constructor of CAspect and
maybe CGridBox.

Best regards,

Oliver
From: Tony C. on
On Sat, 24 Apr 2010 22:36:59 +0200, Oliver Regenfelder
<oliver.regenfelder(a)gmx.at> wrote:

>Hello,
>
>Tony C. wrote:
>> Ok
>>
>> I changed the 2 inner arrays inside the CGridbox object.
>>
>> Instead of being arrays of CAspect, I changed them to
>>
>> arrays of type int...and I get no stack overflow errors and
>>
>> the dialog comes up just fine...
>>
>>
>>
>> ==> So when I have an array of objects inside another type
>> of object, do I need to somehow dynamically allocate memory
>> for the array of inner obects?
>
>No.
>
>> Some special kind of constructor for the inner ojects of type
>> CAspect in my case?
>
>Normally not. Could you post at least the Constructor of CAspect and
>maybe CGridBox.
>
>Best regards,
>
>Oliver

======================================
///CASPECT.CPP
// Aspect.cpp : implementation file
//

#include "stdafx.h"
#include "AstroCalcVC1.h"
#include "Aspect.h"


// CAspect

//IMPLEMENT_DYNAMIC(CAspect, CWnd)

CAspect::CAspect()
{

dbDegr1 = 0;
dbDiff = 0;
intSubType = 0;
intAspNo = 0;


}

CAspect::~CAspect()
{
}


CAspect& CAspect::operator=(const CAspect &A)
{

this->P1 = A.P1;
this->P2 = A.P2;
this->dbDegr1 = A.dbDegr1;
this->dbDiff = A.dbDiff;
this->intSubType = A.intSubType;
this->intAspNo = A.intAspNo;
this->chGlyph1 = A.chGlyph1;
this->dtCalc = A.dtCalc;
this->dtEnd = A.dtEnd;
this->dtStart = A.dtStart;
this->dtExact = A.dtExact;
this->strAspect1 = A.strAspect1;

return *this;

}


//BEGIN_MESSAGE_MAP(CAspect, CWnd)
//END_MESSAGE_MAP()



// CAspect message handlers

=================================================
// GridBox.cpp : implementation file
//

#include "stdafx.h"
#include "AstroCalcVC1.h"
#include "GridBox.h"


// CGridBox



CGridBox::CGridBox()
{


}

CGridBox::~CGridBox()
{
}




// CGridBox message handlers


========================================


CGridbox.cpp and CAspect.cpp
 |  Next  |  Last
Pages: 1 2 3
Prev: PropertyPage Buttons
Next: StringCchCopy question