访问违规读取传递指针方法的位置

时间:2018-03-12 03:22:33

标签: c++ pass-by-reference access-violation

我似乎无法弄清楚为什么我遇到了以下错误:访问违规读取位置。

我的主要代码中有这个代码。正如您所看到的,我正在创建“商店”。和电影'堆上的值并传递它们的指针。

Store* tempStore = new Store();
tempStore -> loadCustomersFromFile("data4customers.txt");
tempStore -> loadMoviesFromFile("data4movies.txt");
Movie* movie = new Movie();
Action* test = Action::create("I", 0, tempStore, 0000, movie);

在第五行,代码不断抛出错误说:

Exception thrown at 0x0F5AF1E0 (ucrtbased.dll) in ass4final.exe: 0xC0000005: Access violation reading location 0x00000000.

现在,create的标题如下:

 static Action* create(string type, string data, Store* store, int id, Movie* movie);

定义是:

  Action* Action::create(string type, string data, Store* store, int id, Movie* movie) {
if (type == "B") {
    return new Borrow(data,store,id, movie);
}
else if (type == "R") {
    return new Return(data,1,store,id, movie);
}
else if (type == "I") {
    return new Inventory(data, store);
}
else if (type == "H") {
    return new History(data, store, id);
}
else {
return nullptr;
}
} 

我已经试图解决这个问题很长一段时间没有运气了。我不认为tempStore和电影在被传递之前就被摧毁了。另外,我尝试在第一行创建'创建'但是我注意到错误是在它进入那里之前抛出的。

任何指针?我错过了什么吗?我看错了吗?

非常感谢您的时间。

0 个答案:

没有答案