我一直在試圖實現一個庫系統代碼。然而,每當我嘗試我的對象傳遞給數組我得到訪問衝突寫入位置0x00000000錯誤C++
訪問衝突寫入位置在Visual Studio 2013
這裏00000000
錯誤是我的代碼 LibrarySystem.cpp
static int bookSize = 0;
static int studentSize = 0;
LibrarySystem::LibrarySystem()
{
books = NULL;
students = NULL;
}
LibrarySystem::~LibrarySystem()
{
}
void LibrarySystem::addBook(const int bookId, const string name, const string authors, const int year){
bool checkBook = false; //checks whether the book is in the list
Book *tempBooks = new Book[bookSize++];
Book newBook;
if (bookSize == 1) {
newBook.setBookId(bookId);
newBook.setBookName(name);
newBook.setAuthors(authors);
newBook.setYear(year);
}
tempBooks[bookSize - 1] = newBook;
cout << tempBooks[1].getAuthors(); // To testing. This is where execution stops
}
}
'tempBooks [1]'在這一點上可能不會被初始化爲任何東西。也許你的意思是'tempBooks [0]'? –
它沒有工作。仍然有這個錯誤 –
我想每當調用函數 –