"例外がスローされずにstd :: mapでclear()メソッドを呼び出そうとしています:読み取りアクセス違反._Pノードが0xDDDDDDDDでした。 "。std :: map.clear()が読み取りアクセス違反をスローしています
//I have narrowed down the error to this group of code
#include "stdafx.h"
#include <map>
#include <iostream>
class Input
{
std::map<int, bool> pressedKeys;
std::map<int, bool> heldKeys;
std::map<int, bool> releasedKeys;
public:
void Update()
{
heldKeys.clear();
pressedKeys.clear();
releasedKeys.clear();
}
};
class Window
{
private:
Input * input;
void Update()
{
input->Update();
}
public:
Window()
{
input = &Input();
while (true)
{
this->Update();
}
}
};
int main()
{
Window w = Window();
}
例外は常に上起こる "heldKeys.clear();" Visual Studioのデバッガで「xtree」というページが表示されます。次のコードは、例外が発生した場所で周りのコードである「のXtree:」
void _Erase(_Nodeptr _Rootnode)
{ // free entire subtree, recursively
for (_Nodeptr _Pnode = _Rootnode; !_Pnode->_Isnil; _Rootnode = _Pnode) //The error occurs here
{ // free subtrees, then node
_Erase(_Pnode->_Right);
_Pnode = _Pnode->_Left;
_Alnode& _Al = this->_Getal();
_Alnode_traits::destroy(_Al, _STD addressof(_Rootnode->_Myval));
_Node::_Freenode0(_Al, _Rootnode);
}
}
私は例外を期待していません。 が、私は例外を取得しています「スロー例外:アクセス違反を読ん _Pnodeが0xDDDDDDDDた。。」これ以上明確化をコメントしてください必要な場合 。
[mcve]を投稿してください。 – PaulMcKenzie
問題はあなたが示したものではありません。あなたが非常に不運でなければ、問題はマイクロソフトのコードではありません。 – chris
また、このコードは実際のプログラムからコピーして貼り付けたのではなく、質問に入力しました。あなたのクラスでは 'heldkeys'が宣言されていますが、' update() '関数では' heldKeys'(資本** K **)を使用します。 – PaulMcKenzie