0
它似乎likt的公共結構是不上課標識.....下面是我的代碼:公共結構沒有在類中標識?
#include <iostream>
#include <cstring>
class Human {
public:
int ID = 32;
Book humanBook;
void printHumanId() {
std::cout << "ID IS : " << ID << std::endl;
}
};
struct DATE {
int year;
int month;
int date;
};
struct Book {
char name[50];
char author[50];
int id;
DATE date;
};
void printBookInfo(Book book) {
std::cout << "Book Author: " << book.author << std::endl;
std::cout << "Book Name: " << book.name << std::endl;
std::cout << "Date : " << book.date.month << "/" << book.date.date << "/" << book.date.year << std::endl;
}
int main() {
Book book1;
DATE date1;
Human Etaferahu;
std::cout << "Date Of Publishing? " << std::endl;
std::cin >> book1.date.date;
std::cout << "Month Of Publishing?" << std::endl;
std::cin >> book1.date.month;
std::cout << "Year Of Publishing?" << std::endl;
std::cin >> book1.date.year;
std::cout << "Book Name ? " << std::endl;
std::cin >> book1.name;
std::cout << "Book Author ? " << std::endl;
std::cin >> book1.author;
Etaferahu.printHumanId();
Etaferahu.humanBook = book1;
printBookInfo(Etaferahu.humanBook);
return 0;
}
,當我運行這段代碼我得到這個錯誤:
Severity Code Description Project File Line Suppression State
Error C3646 'humanBook': unknown override specifier Struct c:\users\amanuel\documents\visual studio 2015\projects\struct\struct\source.cpp 8
Severity Code Description Project File Line Suppression State
Error C2039 'humanBook': is not a member of 'Human' Struct c:\users\amanuel\documents\visual studio 2015\projects\struct\struct\source.cpp 53
Severity Code Description Project File Line Suppression State
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Struct c:\users\amanuel\documents\visual studio 2015\projects\struct\struct\source.cpp 8
Severity Code Description Project File Line Suppression State
Error C2039 'humanBook': is not a member of 'Human' Struct c:\users\amanuel\documents\visual studio 2015\projects\struct\struct\source.cpp 54
讓我怎麼解決?如果我把它放在底部,那麼它就不會知道人類是什麼類的,而且我不能在課堂上做類比(我認爲),就像我可以用函數做的那樣 – amanuel2
你是什麼意思? 「書」課不需要知道「人」是什麼。它不使用它。我們中的一個人很困惑。 –
我知道......但我只是在課堂上練習我的技能。正如我在現在的情節(https://www.youtube.com/watch?v=b8Luumpu_kE&index=25&list=PLS1QulWo1RIYSyC6w2-rDssprPrEsgtVK)...無論如何,我可以解決這個問題,或者它是一個nono? – amanuel2