.h ファイルで std::map を宣言しました
#include "pl.h"
#include <conio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
#include <map>
using namespace std;
class ReadingXDSLfile
{
public:
ReadingXDSLfile();
~ReadingXDSLfile();
void readDotXDSLFile(string fileName, ifstream &file);
void writeNodesList();
protected:
typedef std::map<std::string, int> nodesMap;
nodesMap nodes;
std::vector<string> nodesName;
std::map<std::string, int>::iterator nodeItr, nodeItr1;
string outFileName;
private:
};
.cpp ファイルで、次のコード行を使用して項目を挿入しようとすると、アクセス違反エラーが発生します
int counter=0;
string strNode;
...
....
....
std::pair<string, int>prNode (strNode, counter);
nodes.insert(prNode);
エラー:
Unhandled exception at 0x0043c5d9 in testMMHC.exe: 0xC0000005: Access violation reading location 0x0000002c.
関数 (.cpp ファイル) で一時マップ変数を宣言したので、挿入できます。しかし、一時マップをヘッダー ファイルで宣言されたグローバル マップにコピーすると、無限ループに入り、終了しません。
これは、ヘッダー ファイルで宣言されたすべてのマップ変数で発生します。