'default constructor of "Library::Transaction" cant be referenced -- it's a deleted function
I really don't know what is wrong with my code, I have only pasted the entire code now (EDIT 1).
#include "../../std_lib_facilities.h"
class Date
{
public:
Date(int y, int m, int d);
//...
private:
int y, m, d;
};
Date::Date(int yy, int mm, int dd)
:y{ yy }, m{ mm }, d{ dd } {}
enum class Genre
{
fiction, nonfiction, periodical, biography, children
};
class Invalid {};
class Book
{
public:
string book_ISBN() const { return ISBN; }
string book_title() const { return Title; }
string book_author() const { return Author; }
Date book_copyright_date() const { return Copyright_Date; }
bool availability() { return available; }
Book(string ISBN, string title, string author, Date date, Genre genre);
void check_out();
void check_in();
private:
string ISBN;
string Title;
string Author;
Date Copyright_Date;
Genre genre;
bool available;
};
void Book::check_out()
{
if (available) available = false;
else throw Invalid{};
}
void Book::check_in()
{
if (!available) available = true;
else throw Invalid{};
}
bool operator==(Book a, Book b)
{
if (a.book_ISBN() == b.book_ISBN())
return true;
else
return false;
}
bool operator!=(Book a, Book b)
{
if (a.book_ISBN() != b.book_ISBN())
return true;
else
return false;
}
ostream& operator<<(ostream& os, Book& book)
{
return os << '\n'
<< "Title: " << book.book_title() << '\n'
<< "Author: " << book.book_author() << '\n'
<< "ISBN: " << book.book_ISBN() << '\n';
}
Book::Book(string isbn, string title, string author, Date date, Genre genre)
:ISBN{ isbn }, Title{ title }, Author{ author }, Copyright_Date{ date }, genre{ genre }, available{ true }
{
int size = 13;
if (!(isbn.size() == size)) throw Invalid{};
for (int i = 0; i < size - 1; i++)
{
if (!isdigit(isbn[i])) throw Invalid{};
}
if (!(isalpha(isbn[size - 1]) || isdigit(isbn[size - 1]))) throw Invalid{};
}
class Patron
{
public:
string patron_username() { return username; }
int patron_libcardno() { return libcard_number; }
int patron_libfees();
bool fee_owed();
private:
string username;
int libcard_number;
int library_fees{ 0 };
};
bool Patron::fee_owed()
{
if (library_fees < 0)
throw Invalid{};
else if (library_fees == 0)
return false;
else
return true;
}
int Patron::patron_libfees()
{
if (fee_owed())
{
return library_fees;
}
else
{
cout << "You dont owe any fee";
return 0;
}
}
class Library
{
public:
struct Transaction
{
Book book;
Patron patron;
Date date;
};
void add_book(Book& b);
void add_patron(Patron& p);
void check_out(Book& b, Patron& p);
private:
vector<Book>Books;
vector<Patron>Patrons;
vector<Transaction>transactions;
};
void Library::add_book(Book& b)
{
Books.push_back(b);
}
void Library::add_patron(Patron& p)
{
Patrons.push_back(p);
}
void Library::check_out(Book& b, Patron& p)
{
bool flag1 = true, flag2 = true;
for (Patron patron : Patrons)
{
if (patron.patron_libcardno() == p.patron_libcardno())
{
for (Book book : Books)
{
if ((book.book_ISBN() == b.book_ISBN()) && (book.availability() == true))
{
b.check_out();
flag1 = false;
flag2 = false;
break;
}
}
if (flag1)
{
throw Invalid{};
}
}
}
if (flag2)
{
throw Invalid();
}
if (p.fee_owed())
{
throw Invalid{};
}
else
{
Transaction transaction;
transactions.push_back(transaction);
}
}
int main()
{
try
{
Book a{ "1234567890123", "boy", "boy", Date{2005, 14, 2}, Genre::fiction };
Book b { "1234567890123", "girl", "girl", Date{2015, 11, 22}, Genre::nonfiction };
cout << (a.book_ISBN() != b.book_ISBN());
cout << a;
}
catch (Invalid)
{
cerr << "oopsie daisy" << '\n';
}
}
Its giving me these two errors:
E1790 the default constructor of "Library::Transaction" cannot be referenced -- it is a deleted function
C2280 'Library::Transacation::Transacation(void)': attempting to reference a deleted function
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
