Hello,

I'm currently writing a program in which I need to check wether a list is empty or not, though that produces me crush in the program when I operate the empty() function on it.

Project.h

class Project{
public: 
	friend class Map;

	bool isProjectOpen;
	list<Map> maps;
	list<Map>::iterator it;
	string Name;

	Project();
};

public ref class MProject{
public:
	Project * _p;
	MProject();
};

Project.cpp

Project::Project(){
	this->isProjectOpen = false;
}

#pragma managed

MProject::MProject(){
	_p = new Project();
}

This is an unmanaged class used in a managed project, hence the wrapper.

if(!project._p->maps.empty())

This is the line the program crushes at(project is defined earlier in the code as Project project and from then until this line of code the maps variable is untouched completely), empty() is a function from Microsoft's list.h's list class.

I can't really give any more details, as I'm not even sure what the error means, as it's not a compiler error, but a run-time error.

If anyone could assist me with this, it would be most appreciated.

Normally, the error you are getting should occur when you operate on "it" (the iterator in Project). It should not occur during the use of the function empty(). This is not normal. Unless you have corrupted the memory somehow, this error should not occur. Make sure it is really occurring at the call to empty() and not at the first use of "it". I would suggest that you try doing the same without using the managed wrapper (use the Project class directly). See if the error is still occurring. Then, try to remove (comment out) all code between the creation of the "project" variable and the call to project.empty() and see if the error still occurs. If the problem is still occurring (and I doubt that very much!), then call Bill Gates and tell him he sucks! Because at that point the problem must be in the implementation of std::list (which btw, is part of the C++ Standard Template Library.. it is only implemented by Microsoft if you are using Visual Studio... the GNU implementations are usually better (comes with MinGw and GCC)).

BTW: you mentioned "list.h"... I hope that you are actually #including <list> and not <list.h>!!

Meh, I solved it... I was either very stupid or very tired right now...

The empty() function wasn't what crushed it, I thought it was because I put a breakpoint on it and the following line to see where it crushes, but I forgot that I was working on an empty list at the time, so it skipped the next line, and I haven't breakpointed the next one after the condition...


What was actually making it crush is that it tried to print a garbage string because the following code wasn't complete =\

Thanks for trying to help, Mike. And btw, I am using VS, that's why I said that about it being implemented, my bad for not mentioning that. I did include <list> and not <list.h>. And seems like no scolding Bill Gates for me today, oh well.

Thanks again for your reply.

This article has been dead for over six months. Start a new discussion instead.