I want to convert a (simple linked) list into a skiplist which is derived from linked list. Inside the conversion ctor which gets a (linked-)list as param, i get a stackoverflow at *. I just call that ctor from main once. How is it possible that new SkipList is called loopwise?
class SkipList : public List {
public:
SkipList(SkipListEl* first) : List (first){};
SkipList(const List& sl){
ListEl* fst = sl.getFirst();
new SkipList(fst); // * <- stackoverflow
while(fst->hasNext()){
new SkipListEl(*fst);
fst = fst->getNext();
}
};
You need to review your basic C++ rules on dynamic object creation.
newcalls the constructor for the object you're creating. By callingnew objectin the constructor forobject, you're getting an infinite loop (infinite recursion, actually) leading to no more stack space.