The recent development of C + + programs on VS has encountered this error:
Debug Assertion failed! Expression:_pfirstblock = = Phead
Click Abort, look at the call stack, found that the exception is generated when the function return, further see is the vector destructor is called to produce, not previously developed C + + project, no experience, this error let me very confused, first, I do not have an F disk on the computer; I did not call the destructor; third, what a mistake.
The first question, probably a virtual partition, the second problem, my vector variable is used within a function body declaration, when the function returns, the automatic variable life end, C + + should call the vector destructor to release the object, at this time an exception occurred.
On the third question, I looked up some information on the internet and found that there are some situations
① confusing debug and release situations, sometimes debug and release required libraries are not the same, if you only import the release of the link library, and did not import the debug link library, and the compile run and select the debug mode, this problem may occur, At this point to add the Debug link library can be resolved.
② may be in a multithreaded module run a single-threaded libraries, within the existence of DLL side is allocated, on the use side is freed, may cause a memory manager in allocating memory, another memory manager in the release of the same piece of memory area, resulting in an error.
C + + STL is single-threaded, I use a vector inside the function, this function in a multithreaded environment, is probably the cause of this error.
One solution is to set the runtime to/MDd
Project Right Button-"Properties-" c/c++= "all options
About the runtime several parameters
Multithreading (/MT)
multithreaded Debugging (/MTD)
multithreaded DLLs (/MD)
Multithreaded debug DLLs (/MDD)
After the name with D is the debug library, the name contains d is a dynamic link, including T is a static link
C run-Time library files
multithread (static link) MT LIBCMT.lib
Debug multithread (static link) MTd LIBCMTD.lib
multithread (dynamic link) MD msvert.lib
Debug multithread (dynamic link) MDd msvertd.lib
Another: Workaround for this error when using std::string
Http://stackoverflow.com/questions/18882760/debug-assertion-failed-expression-pfirstblock-phead
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Debug Assertion failed! Expression: _pfirstblock = = Phead