   Problems with std::list
  I have a strange error, just declaring a list like this causes my program to crash with the error:*** glibc detected *** ./client: corrupted double-linked list: 0x0000000001da0f50 ***#ifndef OGRE_VIEW#define OGRE_VIEW#include <list>#include "IView.h"#include "IViewListener.h"#include "IModelListener.h"namespace NextGen {class OgreView : public IView, IModelListener {    public:    OgreView();    ~OgreView();    void render();    void registerListener(IViewListener*);    void objectCreated(std::string);    void objectDestroyed(std::string);    void propertyChanged(std::string);    private:std::list<IViewListener*> listeners;};}#endifI even tried this and it still crashes.std::list<int> listeners;I am using a list in a similar way in another part of my code and there it works. Any ideas?   
  Probably because somewhere else in your program you accidentally overwrote memory which belonged to part of that list.   ;  Try:int padding1[256];std::list<int> listeners;int padding2[256];If that 'fixes' the crash, then Sneftel is most certainly right.   ;  Yeah, that "fixed" the problem.In my main.cpp I have something like this:    IModel *model = new Model();    IView *view = new OgreView();    IController *controller = new OISController();    LoginLogic *logic = new LoginLogic();I changed it to:    IModel *model = new Model();    OgreView *view = new OgreView();    IController *controller = new OISController();    LoginLogic *logic = new LoginLogic();I also changedclass OgreView : public IView, IModelListener {to class OgreView : public IView, public IModelListener {That is all I remember doing and suddenly it worked, for some reason. I even changed the code back to its original when it crashed but the error won't show up again.What I am doing to refactoring my client with a better design, all my code is currently just declarations and empty functions bodies so I have no idea how I managed to overwrite that memory.;  Were you using C-style casts to cast from OgreView to IModelListener, since it was private inherited?   ;  No, I always used dynamic_cast for that:    IModel *model = new Model();    IView *view = new OgreView();    IController *controller = new OISController();    LoginLogic *logic = new LoginLogic();    model->registerListener(dynamic_cast<IModelListener*>(view));    view->registerListener(dynamic_cast<IViewListener*>(controller));    view->registerListener(dynamic_cast<IViewListener*>(controller));    controller->registerListener(dynamic_cast<IControllerListener*>(logic));;  That's an extreme amount of unnecessary casting. Not that it's in a performance critical part of code. It's just clear that you dont understand what's going on. There's no need to explicitly downcast. Especially not with dynamic_cast.you may have dangling references or over run your array bounds somewhere. Do you do any unchecked array access, memcpy, and how sure are you of your pointer lifetime management, do you practice the rule of 3? Can't rule out unitialized variables though. But it's likely in any "naughty" code that you've written trying to write fast or clever code.I suggest you use ref counted pointers until you are more experienced, and by then you will only want to use them.   ;  What does OgreView's constructor look like, and what other variables exist in that class?   ;Quote:That's an extreme amount of unnecessary casting. Not that it's in a performance critical part of code. It's just clear that you dont understand what's going on. There's no need to explicitly downcast. Especially not with dynamic_cast.You are right, reading up on implicit type conversions on classes now.Quote:you may have dangling references or over run your array bounds somewhere. Do you do any unchecked array access, memcpy, and how sure are you of your pointer lifetime management, do you practice the rule of 3? Can't rule out unitialized variables though. But it's likely in any "naughty" code that you've written trying to write fast or clever code.Yeah that seems like a good explanation, except for the fact that I my entire program does not have any code, as I stated before I am refactoring an existing program. All I have for the moment is class declarations and pretty much empty function bodies.Quote:I suggest you use ref counted pointers until you are more experienced, and by then you will only want to use them.That is a good point, reading up on auto_ptr now. Here is my code for OgreView.h and OgreView.cpp:OgreView.h#ifndef OGRE_VIEW#define OGRE_VIEW#include <list>#include "IView.h"#include "IViewListener.h"#include "IModelListener.h"namespace NextGen {class OgreView : public IView, public IModelListener {    public:    OgreView();    ~OgreView();    void render();    void registerListener(IViewListener*);    void objectCreated(std::string);    void objectDestroyed(std::string);    void propertyChanged(std::string);    private:std::list<IViewListener*> listeners;};}#endifOgreView.cpp#include <iostream>#include "OgreView.h"using namespace std;using namespace NextGen;OgreView::OgreView() {    cout << "OgreView"<< endl;}OgreView::~OgreView() {    cout << "~OgreView"<< endl;}void OgreView::registerListener(IViewListener *listener) {    listeners.push_back(listener);    cout << "OgreView registerListener"<< endl;}void OgreView::render() {    cout << "OgreView render"<< endl;}void OgreView::objectCreated(string id) {}void OgreView::objectDestroyed(string id) {}void OgreView::propertyChanged(string id) {};  None of the code you are showing is helping. There's either something more in this class that you are not showing, or the problem is in other code.   