Are you sure the code you posted is correct? It shouldn't compile... QList<DElement> and QList<DElement*> types are not compatible and you are treating them as such, so there is obviously some typo here.
Are you sure the code you posted is correct? It shouldn't compile... QList<DElement> and QList<DElement*> types are not compatible and you are treating them as such, so there is obviously some typo here.
Ah, sorry, they should all be QList<DElement *> *.
Will there be a memory leak if I remove "delete prev;"? The Stack destructor deletes the list contents, so I guess not. Removing the line didn't make it work. Seems the pointers are invalid before undo() is called.
Whew! I figured it out. The operators were deleting the objects. Sorry, there was no way you could have known that. I'm developing an arbitrary-precision RPN calculator program. Do you think I should start a sourceforge project? It's still in the very early stages obviously...
Last edited by space_otter; 18th June 2010 at 19:27.
Does QList support abstract classes though?
What do you mean? You can store anything you like in a QList, but if you're trying to store classes derived from some abstract base class, you'll have to store pointers to the base class, not the derived classes themselves. That's how C++ handles such things.
QList itself, however, doesn't care what you store in it, as long as all the elements match the template type.
Bookmarks