Book 继承 LibraryItem
class Book : public LibraryItem {
这是我在父类中使用构造函数的尝试。
Book::Book(std::string title, std::string callNumber, std::string publisher, std::string location, int year, std::string authors, std::string ISBN, std::string subject, std::string edition) {
LibrayItem(title, callNumber, publisher, location, 'B', year);
this->authors = authors;
this->ISBN = ISBN;
this->subject = subject;
this->edition = edition;
}
g++ 给了我:
LibraryItem.cpp: 在构造函数'Book::Book(std::string, std::string, std::string, std::string, int, std::string, std::string, std::string, std ::string)': LibraryItem.cpp:72:62: error: 'LibrayItem' 未在此范围内声明 LibrayItem(title, callNumber, publisher, location, 'B', year);
于是我搜了一下,发现Implicitly call parent constructors。我试过:
Book::Book(std::string title, std::string callNumber, std::string publisher, std::string location, int year, std::string authors, std::string ISBN, std::string subject, std::string edition) : LibrayItem(title, callNumber, publisher, location, 'B', year) {
[...]
}
g++ 给了我:
LibraryItem.cpp: 在构造函数'Book::Book(std::string, std::string, std::string, std::string, int, std::string, std::string, std::string, std ::string)': LibraryItem.cpp:71:193: 错误: 类 'Book' 没有任何名为 'LibrayItem' 的字段 Book::Book(std::string title, std::string callNumber, std::string出版商,std::string 位置,int 年,std::string 作者,std::string ISBN,std::string 主题,std::string 版本):LibrayItem(标题,callNumber,出版商,位置,'B',年) {
我不知所措,我检查了 Book 的头文件,它确实公开继承了 LibraryItem,所以我不确定问题出在哪里。
class Book : public LibraryItem {
private:
[...]
public:
Book();
Book(std::string, std::string, std::string, std::string, int, std::string, std::string, std::string, std::string);
};