I'm trying to call a method called addBook but I keep getting some errors and I'm not sure what do these errors means.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void Bookshelf::addBook(int ID, string Title, string Author, vector<Book*> myBook){
cout << "Enter an ID:";
cin >> ID;
cout << "Enter a title:";
cin >> Title;
cout << "Enter an author:";
cin >> Author;
Book *mybook = new Book(ID, Title, Author);
vector<Book*> listofBooks;
listofBooks.push_back(mybook);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int main(){
vector <Book*> myBook;
Bookshelf * myBookshelf = new Bookshelf;
myBookshelf->addBook(int ID, string Title, string Author, vector<Book*> myBook); //error: int should be preceded by ')'
//function does not take 0 arguments
//syntax error:')'
return 0;
}
myBookshelf->addBook(int ID, string Title, string Author, vector<Book*> myBook); //error: int should be preceded by ')'
You need to fill in the values for the book you're adding when you call the function.
Also the vector that you pass to the function will not contain anything when the function is called as vector listofBooks is declared in the function and will be destroyed when the function ends, probably pass the vector into the function as a reference which means changing your function to something like: