"No matching function for call to 'book::book()'"

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);

library l(2000);

l.addBook(book1);
l.addBook(book2);
l.addBook(book3);

l.showBooks();


return 0;
}

library.h:

#ifndef LIBRARY
#define LIBRARY
#include <string>


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();
};

#endif

library.cpp:

#include "library.h"
#include <iostream>


using namespace std;

book::book(string title, string author, int publicationYear)
{
this->title = title;
this->author = author;
this->publicationYear = publicationYear;
this->ID = ID;

ID++;
}

book::~book()
{

}



library::library(int maxAmountOfBooks)
{
if (maxAmountOfBooks < 0)
cout << "Your max book amount cannot be less than 0!" << endl;

else {
currentAmountOfBooks = 0;
this->maxAmountOfBooks = maxAmountOfBooks;
books = new book[maxAmountOfBooks];
}

}

library::~library()
{
delete []books;
}

void library::addBook(book Book)
{

currentAmountOfBooks++;

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.

Topic archived. No new replies allowed.