Runtime error when trying to use a superclass in C++
SOLVED * Actually the error happened because It wasn't using the methods of the subclass cause they were implemented up in the superclass, that's why it worked if called from a ListaIterador class but don't if called from the upper class.
Hi I created a ListIterator class of a generic type, it extends Iterator so I did implement the iterator's methods in t开发者_如何学Che ListIterator class. The idea is to create an iterator just for using the methods that are available from the Iterator class (read only methods). First I create a ListIterator, insert some things, and then I want to create an iterator object and use the readonly methods but over the list. I hope I made myself clear, note that I am coding in spanish, so Iterador means Iterator, Insertar is Insert, also Avanzar means Next.
this code is throwing a runtime execution error and don't know why, maybe you can give me a solution
ListaIterable<int> *iter = new ListaIterable<int>;
Iterador<int> *ITERADOR = iter;
iter->Insertar(123); //note here I use iter and not ITERATOR for inserting.
iter->Insertar(987); //also here
cout << ITERADOR->ElementoActual()<<endl; //now this method should show the element
ITERADOR->Avanzar() // means next()
cout << ITERADOR->ElementoActual()<<endl;
Actually the error happened because It wasn't using the methods of the subclass cause they were implemented up in the superclass, that's why it wo
精彩评论