Hi,
I want to write a class that returns a pointer to any data in an array:
class CData
{
private:
struct
{
void* pVoid;
int iLen;
}data;
public:
void SetData (void* pVoid);
void* GetData (int iNum);
};
void CData::SetData (void* pVoid)
{
data.pVoid = pVoid;
data.iLen = iLen;
}
void* CData::GetData (int iNum)
{
return data.pVoid + iNum*iLen; }
With normal data arrays this isn't a problem, but for structures like this I need some help:
struct CHILD
{
TCHAR szString [50];
int iInt;
};
struct MASTER
{
CHILD* pChild;
TCHAR szString [50];
int iInt;
};
static MASTER master [3];
static CHILD child;
_tcscpy (child.szString, TEXT ("Child main"));
child.iInt = 12;
master[0].pChild = master[2].pChild = &child;
master[1].pChild = new CHILD;
master[1].pChild->iInt = 11;
_tcscpy (master[1].pChild->szString, TEXT ("Child 1"));
_tcscpy (master[0].szString, TEXT ("Master 0"));
_tcscpy (master[1].szString, TEXT ("Master 1"));
_tcscpy (master[2].szString, TEXT ("Master 2"));
master[0].iInt = 20;
master[1].iInt = 21;
master[2].iInt = 22;
Returning data from the MASTER structure isn't a problem, but returning data from the CHILD structs is a little bit more complicated because the structs are not "aligned" in the memory(?) So i guesse I have to work with pointers to pointers, but I have no idea how to start, so any ideas?