-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
}
};
}
その後、私は、グローバル関数void start_menu()
で呼ばれるようにしたいが、私はBooks MyBooks;
のように定義されてBooks
クラスのオブジェクトを作成する際に、上記のコードは、私は、このエラーを与えたclass Books{}
あります
をerror: 'Books' was not declared in this scope.
これはグローバル関数void start_menu()
後Books
クラスです:ベース
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();
};
「書籍」は機能の前後に宣言されていますか? – NathanOliver
@ NathanOliverでも定義が必要です。 – Incomputable
@Incomputable Trueですが、後者または別のファイルから来る可能性があります。 – NathanOliver