EDN Admin
Well-known member
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium I have a C++ DLL project that contains a class that contains a static deque and some methods that operate on the deque. It works when compiled in release mode. However, in debug
mode it gives an “Expression: deque iterator not dereferencable” debug assertion failure.
<p style="margin-bottom:0in <span style=" <span style="font-size:medium
<p style="margin-bottom:0in <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium My class header file is:
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff #pragma<span style="color:#000000
<span style="color:#0000ff once
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff #include<span style="color:#000000
<span style="color:#a31515 <deque>
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff class<span style="color:#000000
<span style="color:#0000ff __declspec<span style="color:#000000 (<span style="color:#0000ff dllexport<span style="color:#000000 )
<span style="color:#2b91af DllClass
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff private<span style="color:#000000 :
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere static<span style="color:#000000 std::<span style="color:#2b91af deque<span style="color:#000000 <<span style="color:#0000ff int<span style="color:#000000 >
staticDeque;
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff public<span style="color:#000000 :
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere DllClass(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere ~DllClass(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere void<span style="color:#000000 ShowMessage(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere void<span style="color:#000000 ClearDeque(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere void<span style="color:#000000 PushDeque(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere void<span style="color:#000000 AtDeque(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium };
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium
<p style="margin-bottom:0in <span style=" <span style="font-size:medium The relevant part of my class .cpp file is:
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff #include<span style="color:#000000
<span style="color:#a31515 "DllClass.h"
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff #include<span style="color:#000000
<span style="color:#a31515 <iostream>
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff using<span style="color:#000000
<span style="color:#0000ff namespace<span style="color:#000000 std;
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 std::<span style="color:#2b91af deque<span style="color:#000000 <<span style="color:#0000ff int<span style="color:#000000 >
<span style="color:#2b91af DllClass<span style="color:#000000 ::staticDeque;
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#2b91af DllClass<span style="color:#000000 :llClass(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#2b91af DllClass<span style="color:#000000 ::~DllClass(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff void<span style="color:#000000
<span style="color:#2b91af DllClass<span style="color:#000000 ::ShowMessage(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere cout<<
<span style="color:#a31515 "from DLL"<span style="color:#000000 ;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff void<span style="color:#000000
<span style="color:#2b91af DllClass<span style="color:#000000 ::ClearDeque(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere staticDeque.clear();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff void<span style="color:#000000
<span style="color:#2b91af DllClass<span style="color:#000000 :ushDeque(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere staticDeque.push_back(3);
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff void<span style="color:#000000
<span style="color:#2b91af DllClass<span style="color:#000000 ::AtDeque(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere if<span style="color:#000000 (!staticDeque.empty())
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere {
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere int<span style="color:#000000 sz = staticDeque.size();
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere int<span style="color:#000000 z = staticDeque.at(0);
<span style="color:#008000 // Gives "deque iterator not dereferencable" runtime error.
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere //<span style="color:#008000; font-family:Times New Roman,serif; font-size:medium; line-height:24px int
z = staticDeque[0]; gives the same error.
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 My solution contains a non-DLL project that calls the DLL methods:
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff int<span style="color:#000000 main(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere cout <<
<span style="color:#a31515 "Hello"<span style="color:#000000 ;
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#2b91af <span style="white-spacere <span style="white-spacere DllClass<span style="color:#000000 dc;
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere dc.ClearDeque();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere dc.PushDeque();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere dc.PushDeque();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere dc.AtDeque();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere dc.ShowMessage();
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere return<span style="color:#000000 0;
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 The clear(), push_back() and size() deque methods work. The at(0) method fails. (If staticDeque[0] is substituted for staticDeque.at(0), the same failure
occurs.) StaticDeque.size() confirmed that the deque contains two elements just before the at() call, so the problem is not that staticDeque is empty when staticDeque.at(0) is called.
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium The debug assertion failure occurs at the “_DEBUG_ERROR” line in the following portion of the deque template Microsoft Visual Studio 11.0/VC/include/deque:
<p style="margin-bottom:0in <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#2b91af <span style="white-spacere <span style="white-spacere reference<span style="color:#000000
operator*() <span style="color:#0000ff const
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere {
<span style="color:#008000 // return designated object
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#2b91af <span style="white-spacere <span style="white-spacere _Mydeque<span style="color:#000000 *_Mycont
= ((<span style="color:#2b91af _Mydeque<span style="color:#000000 *)<span style="color:#0000ff this<span style="color:#000000 ->_Getcont());
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="color:#0000ff #if<span style="color:#000000
<span style="color:#6f008a _ITERATOR_DEBUG_LEVEL<span style="color:#000000 == 2
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere if<span style="color:#000000 (_Mycont
== 0
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere ||
<span style="color:#0000ff this<span style="color:#000000 ->_Myoff < _Mycont->_Myoff
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere || _Mycont->_Myoff + _Mycont->_Mysize <=
<span style="color:#0000ff this<span style="color:#000000 -<span style="white-spacere
>_Myoff)
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere {
<span style="color:#008000 // report error
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#6f008a <span style="white-spacere <span style="white-spacere _DEBUG_ERROR<span style="color:#000000 (<span style="color:#a31515 "deque
iterator not dereferencable"<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#6f008a <span style="white-spacere <span style="white-spacere _SCL_SECURE_OUT_OF_RANGE<span style="color:#000000 ;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere }
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium Stepping through the above code in debug mode revealed that this->_Myproxy and _Mycont are zero, with _Mycont == 0 directly causing the assertion failure.
Adding the line
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium #define _ITERATOR_DEBUG_LEVEL 0
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium to the .cpp file results in an unhandled exception rather than the debug assertion failure.
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium I am using Microsoft Visual Studio Express 2012 for Windows Desktop. I got the same results using Microsoft Visual Studio C++ 2010 Express.
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium Does anyone know why referencing a specific element of a static deque fails in debug mode and how it could be made to work? Possible causes that crossed my
mind include:
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -a bug in the Express versions;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -the fact that the static deque is in a DLL;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -the fact that the static deque is in a DLL having the NOENTRY property (i.e. no
Dllmain();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -the fact that the static deque is in a DLL class declared with
<span style="color:#0000ff __declspec(<span style="color:#0000ff dllexport);
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -the fact that the static deque is in a DLL project of a solution which also includes
a non-DLL project;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -some solution, project or class property is not set correctly;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium but I really have no clue.
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:small
<p style="margin-bottom:0in
<br/>
View the full article
<p style="margin-bottom:0in <span style=" <span style="font-size:medium I have a C++ DLL project that contains a class that contains a static deque and some methods that operate on the deque. It works when compiled in release mode. However, in debug
mode it gives an “Expression: deque iterator not dereferencable” debug assertion failure.
<p style="margin-bottom:0in <span style=" <span style="font-size:medium
<p style="margin-bottom:0in <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium My class header file is:
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff #pragma<span style="color:#000000
<span style="color:#0000ff once
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff #include<span style="color:#000000
<span style="color:#a31515 <deque>
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff class<span style="color:#000000
<span style="color:#0000ff __declspec<span style="color:#000000 (<span style="color:#0000ff dllexport<span style="color:#000000 )
<span style="color:#2b91af DllClass
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff private<span style="color:#000000 :
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere static<span style="color:#000000 std::<span style="color:#2b91af deque<span style="color:#000000 <<span style="color:#0000ff int<span style="color:#000000 >
staticDeque;
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff public<span style="color:#000000 :
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere DllClass(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere ~DllClass(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere void<span style="color:#000000 ShowMessage(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere void<span style="color:#000000 ClearDeque(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere void<span style="color:#000000 PushDeque(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere void<span style="color:#000000 AtDeque(<span style="color:#0000ff void<span style="color:#000000 );
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium };
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium
<p style="margin-bottom:0in <span style=" <span style="font-size:medium The relevant part of my class .cpp file is:
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff #include<span style="color:#000000
<span style="color:#a31515 "DllClass.h"
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff #include<span style="color:#000000
<span style="color:#a31515 <iostream>
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff using<span style="color:#000000
<span style="color:#0000ff namespace<span style="color:#000000 std;
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 std::<span style="color:#2b91af deque<span style="color:#000000 <<span style="color:#0000ff int<span style="color:#000000 >
<span style="color:#2b91af DllClass<span style="color:#000000 ::staticDeque;
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#2b91af DllClass<span style="color:#000000 :llClass(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#2b91af DllClass<span style="color:#000000 ::~DllClass(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff void<span style="color:#000000
<span style="color:#2b91af DllClass<span style="color:#000000 ::ShowMessage(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere cout<<
<span style="color:#a31515 "from DLL"<span style="color:#000000 ;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff void<span style="color:#000000
<span style="color:#2b91af DllClass<span style="color:#000000 ::ClearDeque(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere staticDeque.clear();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff void<span style="color:#000000
<span style="color:#2b91af DllClass<span style="color:#000000 :ushDeque(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere staticDeque.push_back(3);
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff void<span style="color:#000000
<span style="color:#2b91af DllClass<span style="color:#000000 ::AtDeque(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere if<span style="color:#000000 (!staticDeque.empty())
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere {
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere int<span style="color:#000000 sz = staticDeque.size();
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere int<span style="color:#000000 z = staticDeque.at(0);
<span style="color:#008000 // Gives "deque iterator not dereferencable" runtime error.
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere //<span style="color:#008000; font-family:Times New Roman,serif; font-size:medium; line-height:24px int
z = staticDeque[0]; gives the same error.
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 My solution contains a non-DLL project that calls the DLL methods:
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#0000ff int<span style="color:#000000 main(<span style="color:#0000ff void<span style="color:#000000 )
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium {
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere cout <<
<span style="color:#a31515 "Hello"<span style="color:#000000 ;
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#2b91af <span style="white-spacere <span style="white-spacere DllClass<span style="color:#000000 dc;
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere dc.ClearDeque();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere dc.PushDeque();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere dc.PushDeque();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere dc.AtDeque();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere dc.ShowMessage();
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere return<span style="color:#000000 0;
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 }
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 The clear(), push_back() and size() deque methods work. The at(0) method fails. (If staticDeque[0] is substituted for staticDeque.at(0), the same failure
occurs.) StaticDeque.size() confirmed that the deque contains two elements just before the at() call, so the problem is not that staticDeque is empty when staticDeque.at(0) is called.
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium The debug assertion failure occurs at the “_DEBUG_ERROR” line in the following portion of the deque template Microsoft Visual Studio 11.0/VC/include/deque:
<p style="margin-bottom:0in <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#2b91af <span style="white-spacere <span style="white-spacere reference<span style="color:#000000
operator*() <span style="color:#0000ff const
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere {
<span style="color:#008000 // return designated object
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#2b91af <span style="white-spacere <span style="white-spacere _Mydeque<span style="color:#000000 *_Mycont
= ((<span style="color:#2b91af _Mydeque<span style="color:#000000 *)<span style="color:#0000ff this<span style="color:#000000 ->_Getcont());
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="color:#0000ff #if<span style="color:#000000
<span style="color:#6f008a _ITERATOR_DEBUG_LEVEL<span style="color:#000000 == 2
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#0000ff <span style="white-spacere <span style="white-spacere if<span style="color:#000000 (_Mycont
== 0
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere ||
<span style="color:#0000ff this<span style="color:#000000 ->_Myoff < _Mycont->_Myoff
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere || _Mycont->_Myoff + _Mycont->_Mysize <=
<span style="color:#0000ff this<span style="color:#000000 -<span style="white-spacere
>_Myoff)
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="white-spacere <span style="white-spacere {
<span style="color:#008000 // report error
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#6f008a <span style="white-spacere <span style="white-spacere _DEBUG_ERROR<span style="color:#000000 (<span style="color:#a31515 "deque
iterator not dereferencable"<span style="color:#000000 );
<p style="margin-bottom:0in <span style=" <span style="font-size:medium <span style="color:#000000 <span style="color:#6f008a <span style="white-spacere <span style="white-spacere _SCL_SECURE_OUT_OF_RANGE<span style="color:#000000 ;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere }
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium Stepping through the above code in debug mode revealed that this->_Myproxy and _Mycont are zero, with _Mycont == 0 directly causing the assertion failure.
Adding the line
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium #define _ITERATOR_DEBUG_LEVEL 0
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium to the .cpp file results in an unhandled exception rather than the debug assertion failure.
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium I am using Microsoft Visual Studio Express 2012 for Windows Desktop. I got the same results using Microsoft Visual Studio C++ 2010 Express.
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium Does anyone know why referencing a specific element of a static deque fails in debug mode and how it could be made to work? Possible causes that crossed my
mind include:
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -a bug in the Express versions;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -the fact that the static deque is in a DLL;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -the fact that the static deque is in a DLL having the NOENTRY property (i.e. no
Dllmain();
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -the fact that the static deque is in a DLL class declared with
<span style="color:#0000ff __declspec(<span style="color:#0000ff dllexport);
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -the fact that the static deque is in a DLL project of a solution which also includes
a non-DLL project;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium <span style="white-spacere <span style="white-spacere -some solution, project or class property is not set correctly;
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:medium but I really have no clue.
<p style="margin-bottom:0in
<p style="margin-bottom:0in <span style="color:#000000 <span style=" <span style="font-size:small
<p style="margin-bottom:0in
<br/>
View the full article