Hello Forum Gurus:
I am trying to figure out how to implement a CArray of a structure that contains within it another CArray.
The outer structure desired is:
struct BASE
{
int BasePoly;
CArray <int,int> AdjTo;
};
and I can declare a member of this in my document:
class CMainDoc : public CDocument
{
// Attributes
public:
CArray <BASE,BASE> m_RawData;
// Implementation
public:
void ReadListForRecursion();
}
My document member function ReadListForRecursion() is going to read data in and dynamically grow based on the input data. The idea is that for each element of m_RawData I will be reading in a single value to fill up .BasePoly and some number of integers to fill up the CArray member AdjTo that is within m_RawData.
I am new with templates and collections of CObjects so I am having a hard time understanding the MSDN Library help. I think it is telling me that I need to create an overridding function ConstructElements (and DestructElements and a few others) because my initial element (the BASE structure) needs to initialize the AdjTo CArray. The MSDN Library example has something like:
"For example, you might override ConstructElements for an array of CPerson objects as follows:
class CPerson : public CObject { . . . };
CArray< CPerson, CPerson& > personArray;
template <> void AFXAPI ConstructElements <CPerson> ( CPerson* pNewPersons, int nCount )
{
for ( int i = 0; i < nCount; i++, pNewPersons++ )
{
// call CPerson default constructor directly
new( pNewPersons )CPerson;
}
}"
But I don't understand how to implement this with what I have. Where do I put this override? How do I write it with what I have at the start of this posting? etc. etc?
Thank you for any help.
David H. Graetz
I am trying to figure out how to implement a CArray of a structure that contains within it another CArray.
The outer structure desired is:
struct BASE
{
int BasePoly;
CArray <int,int> AdjTo;
};
and I can declare a member of this in my document:
class CMainDoc : public CDocument
{
// Attributes
public:
CArray <BASE,BASE> m_RawData;
// Implementation
public:
void ReadListForRecursion();
}
My document member function ReadListForRecursion() is going to read data in and dynamically grow based on the input data. The idea is that for each element of m_RawData I will be reading in a single value to fill up .BasePoly and some number of integers to fill up the CArray member AdjTo that is within m_RawData.
I am new with templates and collections of CObjects so I am having a hard time understanding the MSDN Library help. I think it is telling me that I need to create an overridding function ConstructElements (and DestructElements and a few others) because my initial element (the BASE structure) needs to initialize the AdjTo CArray. The MSDN Library example has something like:
"For example, you might override ConstructElements for an array of CPerson objects as follows:
class CPerson : public CObject { . . . };
CArray< CPerson, CPerson& > personArray;
template <> void AFXAPI ConstructElements <CPerson> ( CPerson* pNewPersons, int nCount )
{
for ( int i = 0; i < nCount; i++, pNewPersons++ )
{
// call CPerson default constructor directly
new( pNewPersons )CPerson;
}
}"
But I don't understand how to implement this with what I have. Where do I put this override? How do I write it with what I have at the start of this posting? etc. etc?
Thank you for any help.
David H. Graetz