我必须实现一个类来表示图书馆中的书籍。对于每本书,我必须指定:标题、作者、ISBN 代码、出版年份和价格。然后我需要创建一个包含图书馆中所有书籍的数组。这是我处理过的代码,这是错误:
错误 C2512:“书”:没有合适的默认构造函数可用
我做错了什么?
Book.h
#ifndef BOOK_H
#define BOOK_H
#include<string>
using namespace std;
class Book
{
private:
string title;
string author;
string code;
string edit;
int year;
double price;
public:
Book();
Book(string t, string a, string c, string e, int y, double p)
{
title=t;
author=a;
code=c;
edit=e;
year=y;
price=p;
}
string GetTitle() const { return title;}
string GetAuthor() const { return author;}
string GetCode() const {return code;}
string GetEdit() const {return code;}
int GetYear() const {return year;}
double GetPrice() const {return price;}
};
#endif
Library.h
#ifndef LIBRARY_H
#define LIBRARY_H
#include"Book.h"
#include<iostream>
class Library
{
private:
Book books[50];
int index;
public:
Library()
{
index=0;
}
void Add(Book book)
{
books[index]=book;
index++;
}
void PrintAll()
{
for (int i = 0; i < index; i++)
{
Book book=books[i];
cout<<book.GetTitle()<<":"
<<book.GetAuthor()<<":"<<book.GetYear()<<endl;
}
}
};
#endif
main.cpp
#include"Library.h"
int main()
{
Library library;
Book b1("title1","author1","code1","edit1",1900,34.5);
library.Add(b1);
Book b2("title2","author2","code2","edit2",1990,12);
library.Add(b2);
library.PrintAll();
}