私のクラスでは、任意のオブジェクトをベクター myCache にプッシュしようとすると、実行時エラーが発生します。ベクトルを適切に初期化していることは知っていますが、なぜこれが起こっているのか困惑しています。
#ifndef CACHE_H
#define CACHE_H
#include <iostream>
#include "cacheblock.h"
using namespace std;
class Cache
{
public:
Cache(int rows, int numWords);
~Cache();
CacheBlock getBlock(int index);
private:
vector<CacheBlock> *myCache;
};
#endif
と
Cache::Cache(int rows, int numWords)
{
myCache = new vector<CacheBlock>;
CacheBlock test(rows, 0, 0);
myCache->push_back(test);
/*
for (int i = 1; i < rows; i++)
{
myCache->push_back(test);
cout << "inside loop\n\n";
}
*/
}
CacheBlock.h:
class CacheBlock
{
public:
CacheBlock(int numWords, int newIndex, int tagNum);
CacheBlock(const CacheBlock &newCacheBlock);
~CacheBlock();
void setData(int numWords, int newIndex, int tagNum);
private:
bool valid;
int index;
int tag;
vector<int> *dataWords;
};
誰でも助けることができますか?