Hello. I am currently building a library in C++ but when I try to compile this, it states there is no matching function for the book constructor. Please help!
main.cpp:
#include <iostream>
#include "library.h"
using namespace std;
int main()
{
const book book1("Diary of a wimpy kid", "Jeff Kinney", 2000);
const book book2("Percy Jackson and the sea of monsters", "Rick Riordan", 2003);
const book book3("Harry Potter", "JK Rowling", 1997);
class book {
private:
std::string title;
std::string author;
int publicationYear;
static int ID;
public:
std::string getTitle() {return title;}
std::string getAuthor() {return author;}
int getPublicationYear() {return publicationYear;}
int getID() {return ID;}
book(std::string, std::string, int);
~book();
static int numberOfBooksAlreadyCreated;
};
class library {
private:
book *books;
int maxAmountOfBooks;
int currentAmountOfBooks;
public:
// returning
int returnCurrentAmountOfBooks() {return currentAmountOfBooks;}
// Constructors and destructors
library(int);
~library();
// Methods
void addBook(book);
book getBook(int);
void showBooks();
};
if (currentAmountOfBooks > maxAmountOfBooks)
cout << "You have succeeded the max amount of books! You cannot have more!" << endl;
else
books[currentAmountOfBooks] = Book;
}
book library::getBook(int Book)
{
if (Book > maxAmountOfBooks || Book < 1)
return books[0];
else
return books[Book];
}
void library::showBooks()
{
for (int i = 0; i++ < currentAmountOfBooks;)
{
cout << "Book " << i << ": " << getBook(i).getTitle() << endl;
}
}
You created a Book constructor with multiple arguments so the compiler will no longer supply the no argument constructor, with your limited "error message" it looks like somewhere you're trying to use the no argument constructor.