2013-06-02 34 views
2

有沒有人有關於如何解決此問題的任何想法?我在網上查看並更改了我的Visual C++設置,但它仍然無效。錯誤LNK2019:函數中引用的無法解析的外部符號_main visual C++

class store 
{ 
public: 
    int MainMenu(); 
    store(); 
private: 
    int main; 
}; 

class customer:store 
{ 
public: 
    int CustomerMenu(); 
    customer(); 
private: 
    int cmenu; 
}; 

class employee:store 
{ 
public: 
    int EmployeeMenu(); 
    employee(); 
private: 
    int emenu; 

}; 

int main() 
{ 
    int main; 
    store a; 
    customer b; 
employee c; 
a.MainMenu(); 
if(main = 1) 
{ 
    c.EmployeeMenu(); 
} 
else if(main = 2) 
{ 
    b.CustomerMenu(); 
} 
else 
{ 
    exit(EXIT_SUCCESS); 
} 
} 

int MainMenu() 
{ 
    int main; 
cout << "Choose an option: " << endl; 
cout << " 1. Administration menu" << endl; 
cout << " 2. Customer menu" << endl; 
cout << " 3. Exit the program" << endl; 
cin >> main; 
return main; 
} 

int CustomerMenu() 
{ 
int cmenu; 
cout << " 1. Search Video" << endl; 
cout << " 2. View Video Titles" << endl; 
cout << " 3. Rent Video" << endl; 
cout << " 4. Exit to the Main Menu" << endl; 
cout << " 5. Exit the program" << endl; 
cin >> cmenu; 
return cmenu; 

} 

int EmployeeMenu() 
{ 
int emenu; 
    cout << " 1. Store Information menu" << endl; 
    cout << " 2. Merchandise Information menu" << endl; 
    cout << " 3. Category Information menu" << endl; 
    cout << " 4. Customer Information menu" << endl; 
    cout << " 5. Employee Information menu" << endl; 
    cout << " 6. Rent a Video" << endl; 
    cout << " 7. Restock Video" << endl; 
    cout << " 8. Sales menu" << endl; 
    cout << " 9. Exit to Main Menu" << endl; 
    cout << " 10. Exit the program" << endl; 
cin >> emenu; 
return emenu; 

} 

store::store() 
{ 
main = 0; 
} 

customer::customer() 
{ 
cmenu = 0; 
} 

employee::employee() 
{ 
emenu = 0; 
} 

它給我:

Store.obj : error LNK2019: unresolved external symbol "public: int __thiscall customer::CustomerMenu(void)" ([email protected]@@QAEHXZ) referenced in function _main 
1>Store.obj : error LNK2019: unresolved external symbol "public: int __thiscall employee::EmployeeMenu(void)" ([email protected]@@QAEHXZ) referenced in function _main 
1>Store.obj : error LNK2019: unresolved external symbol "public: int __thiscall store::MainMenu(void)" ([email protected]@@QAEHXZ) referenced in function _main 
+0

爲什麼你有一個名爲'main'的變量? – Elazar

+0

更不用說'if(main = 1)'永遠是真的。你的意思是'=='。 – Elazar

回答

4

您正在實施CustomerMenu()EmployeeMenu()作爲正常功能,而不是類成員。實施應該是;

int customer::CustomerMenu() 
{ 
... 

int employee::EmployeeMenu() 
{ 
... 
+0

非常感謝! – Tiffany

1
if(main = 1) 
{ //^^should be ==, same as the one below 
    c.EmployeeMenu(); 
} 
else if(main = 2) 
{ 
    b.CustomerMenu(); 
} 

成員函數應具有範圍解析操作符來定義:

int CustomerMenu() 

應該是:

int Customer::ustomerMenu() 

小點:

class employee:store 

在這裏,您使用private inheritance,你真的需要想想你是否需要與否。

+0

(OP是新手,顯然他*不需要私有繼承。) 語法應該是'class employee:public store'。但'僱員'從'store'繼承是不太可能的。 – Elazar

+0

@Elazar我完全同意你的看法。 – taocp

+0

感謝你們雙方的意見。正如Elazar聲稱我是初學者。 – Tiffany

1

您的成員函數實現需要正確定義。例如:

int CustomerMenu() 

應該是:

int customer::CustomerMenu(void) 

等等。

相關問題