smick
25th September 2011, 13:43
Hi
I am using Qlist of objects of type MyObj in an instance of class AClass
Should I store the as a list of pointers to MyObj
QList <MyObj*> mylist;
The function to add items to my list is as follows
void AClass::addToList(const QList <MyObj> &items)
{
foreach(MyObj m, items)
{
MyObj mm = new MyObj(m);
mylist.append(mm);
}
}
OR a list of MyObj instances and i add to the list as follows
QList <MyObj> mylist;
void AClass::addToList(const QList <MyObj> &items)
{
mylist.append(items);
}
Which of the two cases above is the best way?
I have a problem removing items from the list as the MyObj class does not have a comparison operator
For example, I have a function to remove items from the list
void AClass::removeFromList(const QList <MyObj> &items)
{
foreach(MyObj m, items)
{
/*
what do I put in here if I want to remove 'items' from mylist
*/
}
}
Regards
I am using Qlist of objects of type MyObj in an instance of class AClass
Should I store the as a list of pointers to MyObj
QList <MyObj*> mylist;
The function to add items to my list is as follows
void AClass::addToList(const QList <MyObj> &items)
{
foreach(MyObj m, items)
{
MyObj mm = new MyObj(m);
mylist.append(mm);
}
}
OR a list of MyObj instances and i add to the list as follows
QList <MyObj> mylist;
void AClass::addToList(const QList <MyObj> &items)
{
mylist.append(items);
}
Which of the two cases above is the best way?
I have a problem removing items from the list as the MyObj class does not have a comparison operator
For example, I have a function to remove items from the list
void AClass::removeFromList(const QList <MyObj> &items)
{
foreach(MyObj m, items)
{
/*
what do I put in here if I want to remove 'items' from mylist
*/
}
}
Regards