-3
我有一個全局函數void start_menu()
,我用它作爲接口。如何在C++中調用全局函數中的類對象?
void start_menu()
{
int x;
cout << " ------------------------------------" << endl;
cout << " WELCOME TO LIBRARY MANAGEMENT SYSTEM" << endl;
cout << "------------------------------------" << endl;
cout << " 1. ABOUT Books " << endl;
cout << " 2. ABOUT Members " << endl;
cout << " CHOOSE:";
cin >> x;
Books MyBooks; //object of books class
do
{
if (x==1)
{
system("cls");
MyBooks.INTR_Books(); //calling function of Books Class
}
};
}
然後,我有class Books{}
,我想在全局函數void start_menu()
被調用,但是當我做Books
類,它被定義爲Books MyBooks;
的對象,上面的代碼給了我這個錯誤:
error: 'Books' was not declared in this scope.
這是後Books
類全局函數void start_menu()
:
class Books
{
public:
string BookName; //name of the Book
string Auth; //Author of the book
string Trans; // translator of the book
string myArray[20];
int BookCode; // code of the book
int BookNum; // number of copies exist
void INTR_Books(); //show interface related to books
void ADD_BOOK();
void DELETE_BOOK();
void SEARCH();
void SHOW_ALL();
void BR_BOOK();
};
在函數之前或之後是否聲明瞭'Books'? – NathanOliver
@NathanOliver,它也需要定義。 – Incomputable
@Incomputable是的,但可以來自後者或來自其他文件。 – NathanOliver