プロジェクトにクラス オブジェクトの 2 つのリストを実装しています。もともと、クラス オブジェクトの 1 つのグループに対して 1 つのベクター コンテナーを使用し、もう 1 つのグループに対してリストを使用していましたが、ベクターの実装をリストに変換したところです。
ベクトルとリストの実装ではすべて問題なく動作しましたが、ベクトルをリストに変換 (および後続のすべてのコードを変更) すると、オブジェクトをリストに push_back (または挿入) しようとすると、未処理の例外が発生します。
PN_test.exe の 0x004184e2 で未処理の例外: 0xC0000005: アクセス違反の読み取り場所 0x00000004。
これは、次の結果として生じます。
.hpp ファイル:
class ssmcSection {
public:
data8* sectStartAddress;
data32 sectSize;
};
std::list<ssmcSection> sections;
.cpp ファイル:
ssmcSection sec0;
sec0.sectStartAddress = memHeadAddress;
sec0.sectSize = 0;
sections.push_back(sec0); //<- DIES IN THIS CALL
リスト ライブラリの例外:
void _Insert(const_iterator _Where, const _Ty& _Val)
{ // insert _Val at _Where
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Where._Getcont() != this)
_DEBUG_ERROR("list insert iterator outside range");
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
_Nodeptr _Pnode = _Where._Mynode();
_Nodeptr _Newnode =
this->_Buynode(_Pnode, this->_Prevnode(_Pnode), _Val); // <- This is where the exception occurs in the list library
_Incsize(1);
this->_Prevnode(_Pnode) = _Newnode;
this->_Nextnode(this->_Prevnode(_Newnode)) = _Newnode;
}
編集::前後の表示
以前の私のクラス定義:
class SMMC {
public:
...
class ssmcSection {
public:
data8* sectStartAddress;
data32 sectSize;
};
class smmcAllocData {
public:
bool allocated;
data8* start;
data8* end;
data32 sectionNum;
};
private:
std::list<smmcAllocData> memMap;
std::vector<ssmcSection> sections;
};
以前の私のクラスの実装:
ssmcSection sec0;
sec0.sectStartAddress = memHeadAddress;
sec0.sectSize = 0;
sections.push_back(sec0);
...
smmcAllocData newSec;
newSec.allocated = true;
newSec.start = memHeadAddress;
newSec.end = memHeadAddress + spaceRequested;
newSec.sectionNum = sections.size()-1;
memMap.push_back(newSec);
すべてうまくいきました。以下に変更点を示します。
後の私のクラス定義:
class SMMC {
public:
...
class ssmcSection {
public:
data8* sectStartAddress;
data32 sectSize;
};
class smmcAllocData {
public:
bool allocated;
data8* start;
data8* end;
data32 sectionNum;
};
private:
std::list<smmcAllocData> memMap;
std::list<ssmcSection> sections; //changed from vector to list
};
後の私のクラスの実装:
ssmcSection sec0;
sec0.sectStartAddress = memHeadAddress;
sec0.sectSize = 0;
sections.push_back(sec0);
...
smmcAllocData newSec;
newSec.allocated = true;
newSec.start = memHeadAddress;
newSec.end = memHeadAddress + spaceRequested;
newSec.sectionNum = sections.size()-1;
memMap.push_back(newSec);
これは「sections.push_back(sec0);」で失敗します。smmcAllocData リストで行っていたのとまったく同じことです...!!??
他のリストコンテナでは機能するのに、これでは機能しない理由がわかりません...リストのすべての例は、これと同じ使用法を示しています。MS VS2010 を使用しています。
何か考えはありますか?? ありがとう!