I have a constructed a copy constructor but what I need to do is to is to add the information that every node has in the list to the add function.
Here is my ShapeList.cpp file (do note it's just part of it):
class ShapeNode {
public:
const Shape* s;
ShapeNode* bak;
ShapeNode* fram;
ShapeNode(){
fram = NULL;
s = NULL;
}
ShapeNode(const Shape* _s, ShapeNode* _bak, ShapeNode* _fram) : s(_s), bak(_bak), fram(_fram) {}
~ShapeNode() {}
int ShapeList::Rkn = 0;
int ShapeList::AntLst = 0;
ShapeList::ShapeList() {
AntLst++;
ny = new ShapeNode(0, 0, 0);
ny->fram = ny->bak = ny;
}
ShapeList::ShapeList(const ShapeList &listofShapes) : ny(NULL) {
NwLst = new ShapeList();
ShapeNode* cur = listofShapes.ny;
ShapeNode* sisList = NULL;
int vrl = 0;
while(vrl < Rkn){
++vrl;
ShapeNode* n = new ShapeNode;
n->s = cur->s;
NwLst->add(n->s);
if(!ny){
ny = n;
sisList = ny;
}else {
sisList->fram = n;
sisList = n;
}
cur = cur->fram;
if (vrl>10) break;
}
}
void ShapeList::add(const Shape& s){
Rkn++;objekt i listan
const Shape* tmpPek = &s;
tmpPek = tmpPek->clone();
ShapeNode *tmp = ny;
ny = new ShapeNode(tmpPek, 0, tmp);
tmp->bak = ny;
}
So my question is this, is it possible to call the function add (to add the nodes shape-object it has) with the copy constructor or do I have to redo it?