AcArray - implementation question

AcArray - implementation question

Anonymous
Not applicable
313 Views
1 Reply
Message 1 of 2

AcArray - implementation question

Anonymous
Not applicable
I am trying to implement AcArray... I need to store an array of objects,
each of which contains an array. Does is my code clean? Below I have my
class definition showing data structures, then the
constructor/desctructor... finally, I have a simple skeleton implementation.
It seems to work OK... but is there anything that needs to be changed to
avoid problems or follow convention??

Thanks,
MS


class CSomeClass
{
public:
CSomeClass();
virtual ~CSomeClass();

struct myStruct
{
AcDbObjectId someObjId;
AcDbObjectIdArray arrObjIds;
};
typedef AcArray ArrMyStruct;
ArrMyStruct arrMyStruct;
};

CSomeClass::CSomeClass()
{
}

CSomeClass::~CSomeClass()
{
while(arrMyStruct.isEmpty())
{
delete ((myStruct*&)arrMyStruct.at(0));
arrMyStruct.removeFirst();
}
}


void someCommand()
{
CSomeClass myClass;

for(int i=0;i {
CSomeClass::myStruct* someInstance=new CSomeClass::myStruct;
myClass.arrMyStruct.append(*someInstance);
}
}
0 Likes
314 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
"Martin Schmid" schrieb im Newsbeitrag
news:[email protected]...
> I am trying to implement AcArray... I need to store an array of objects,
> each of which contains an array. Does is my code clean? Below I have my
> class definition showing data structures, then the
> constructor/desctructor... finally, I have a simple skeleton
implementation.
> It seems to work OK... but is there anything that needs to be changed to
> avoid problems or follow convention??
>
> Thanks,
> MS
>
>
> class CSomeClass
> {
> public:
> CSomeClass();
> virtual ~CSomeClass();
>
> struct myStruct
> {
> AcDbObjectId someObjId;
> AcDbObjectIdArray arrObjIds;
> };
> typedef AcArray ArrMyStruct;
> ArrMyStruct arrMyStruct;
> };
>
> CSomeClass::CSomeClass()
> {
> }
>
> CSomeClass::~CSomeClass()
> {

eiher this is wrong......

> while(arrMyStruct.isEmpty())
> {
> delete ((myStruct*&)arrMyStruct.at(0));
> arrMyStruct.removeFirst();
> }
> }
>
>
> void someCommand()
> {
> CSomeClass myClass;
>



> for(int i=0;i > {

...or this one..

> CSomeClass::myStruct* someInstance=new CSomeClass::myStruct;
> myClass.arrMyStruct.append(*someInstance);
> }
> }

If you want to store dynamically allocated objects in an array, your typedef
has to look like this:
typedef AcArray ArrMyStruct. (You are storing Pointers, not
Objects)
Then deleting the content in the dtor is correct. (BTW, if you
want to clean an AcArray, setLogicalLength(0) is much more efficient and
convinient that a while loop).
If you want to store Objects by value, your typedef is correct, but then you
will crash in the dtor as you
delete the memory twice

>
>
>
0 Likes