About Store Forum Documentation Contact



Post Reply 
Memb question
Author Message
Brainache Offline
Member

Post: #1
Memb question
Ok,

I need to have a Memb of pointers to classes that are stored in other Memb's...

For example: (psuedocode)

class cData
{
Int blah;
Str blah2;
};


then... i have

class cDataSet
{
Int something;
Str somethingelse;
Memb<cData> mData
};


Now I have a collection of these classes...

Memb<cDataSet> datasets;

Ok.. now what I want is to create a list of pointers to all the data in the different sets...

Memb<cData*> all_data;




FREPA(datasets)
{
for (Int z=0;z<datasets.mData.elms();z++)
{
// this is where im boggled... either getting casting errors, or crashes...
// i know that what i have here is wrong and wont compile.. but what should it be?
cData *data = all_data.New();
data = &datasets[i].mData[z];
}
}



Thanks!
01-12-2009 08:39 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: Memb question
Hi,

maybe something like this should help

Code:
struct cData
{
   Int blah;
   Str blah2;
};

struct cDataSet
{
   Int something;
   Str somethingelse;
   Memb<cData> mData;
};

Memb<cDataSet> datasets;

Memb<cData*> all_data;


void test()
{
   FREPA(datasets)
   {
      cDataSet &dataset=datasets[i]; // get reference to i-th 'dataset'
      FREPA(dataset.mData) // iterate through all elements in 'dataset'
      {
         cData *&data = all_data.New(); // here you need to store a reference to pointer, not only pointer like you had : cData *data = all_data.New();
         data = &dataset.mData[i];
      }
   }
}
01-12-2009 09:44 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
Re: Memb question
oh and one important thing, since your using pointer references to objects, you shouldnt use Memb but Memx

class cData
{
Int blah;
Str blah2;
};


then... i have

class cDataSet
{
Int something;
Str somethingelse;
Memb<cData> mData // here Memx
};


Memb<cDataSet> datasets; // here Memx

because when you remove a element in Memb, other element in the container gets his address changed, while in Memx theyre always constant

check docs/programming/memory containers for more info
01-13-2009 04:04 PM
Find all posts by this user Quote this message in a reply
Brainache Offline
Member

Post: #4
Re: Memb question
Excellent - thanks for the enlightenment.
01-13-2009 04:50 PM
Find all posts by this user Quote this message in a reply
Post Reply