堆栈超出范围.也许没有正确地称呼它
Stack going out of scope. Maybe not calling it correctly?
我遇到的问题是矢量超出了范围。构造函数和另一个方法都被一个接一个地调用,但问题是在构造函数运行后,向量超出了范围。有人想过如何解决这个问题吗?我以为我修好了,但只会让事情变得更糟。
标题:
struct input
{
bool dirtyBit;
int statusBit; //0 not in cache, 1 in cache, 2 in 2nd cache
bool writeStatus; //write = 1 read = 0
int address;
int indivBlockIndex;
int indivBlockOffset;
};
class Cache
{
public:
vector<input > dataBase;
Cache(string);
~Cache();
void DirectMapped(int, int);
};
实现:
Cache::Cache(string infile)
{
ifstream in(infile);
string readWriteStatus;
int Addr;
while (in >> readWriteStatus >> hex >> Addr)
{
input contents;
//contents = new input;
if (readWriteStatus == "read")
contents.writeStatus = true;
else if (readWriteStatus == "write")
contents.writeStatus = false;
contents.address = Addr;
contents.dirtyBit = false;
contents.statusBit = 0;
contents.indivBlockIndex = -1;
contents.indivBlockOffset = -1;
dataBase.push_back(contents);
}
}
Cache::~Cache(){}
void Cache::DirectMapped(int cacheSize, int blockSize)
{
//initial stats needed
int blockCount = cacheSize/blockSize; //number of total blocks
//clear out the cache
for (int i = 0; i < dataBase.size(); i++)
dataBase[i].statusBit = 0;
//other stuff not related to question
}
main:
int main(int argc, char *argv[])
{
//string in = argv[1];
string inputfile = "C:/Users/Christopher/Downloads/testprac";
string infile = inputfile.append(".trace");
Cache myCache(infile);
// Parse Command Line Argument
// if(argc != 2)
// cout << "ERROR: Improper Number of Arguments" << endl;
// else
// {
int i = 1024, j = 8;
myCache.DirectMapped(i,j);
system ( "pause");
return 0;
}
main在两条连续的线路中直接从myCache(infile)
到myCache.DirectMapped(i,j)
进行调用。
谢谢你们的帮助。我真的很感激。
函数的"第一行之前"是调试器经常无法显示任何正确值的地方(因为事情还没有设置好)。
实际上,向量不在范围内的可能性更大。
在得出任何结论之前,先进入函数。
相关文章:
- 如何正确地将分支添加到已存在的树中
- 如何正确地将带有指针的数组传递给函数
- 如何正确地推回然后遍历堆中对象的向量?
- 我是否不正确地集中了这些字符数组?
- 如何通过另一个对象中的命令正确地从一个对象返回数据
- 我怎样才能通过友谊正确地履行我的职能?
- C++:如何正确地将 deque::front() 返回的变量从函数中传递出去?
- 我应该如何正确地将packaged_task移动到 lambda?
- 如何正确地将SHA1CryptoServiceProvider转换为c ++?
- 如何正确地对 constexpr 函数进行单元测试
- 我的动态链接队列在同一输出流中调用时不正确地输出三个返回函数
- 如何正确地将boost::asio::buffers_iterator转换为InputIterator
- 如何正确地检查变量char中包含的字母
- 当试图交换可变模板类时,如何正确地重载operator=
- 如何正确地将 boost::optional<std::chrono::d uration> 作为函数参数?
- 如何在C++中正确地将我的语言字符输出到HTML文件中
- 如果我的类正确地管理了一个资源,那么拥有智能的poointer有什么意义
- 如何正确地编写这些条件,以便它们在控制台中工作
- 正确地编写一个类,并将pthread与vlc库和c++一起使用
- 堆栈超出范围.也许没有正确地称呼它