我有幾個問題。首先,我會給一些僞代碼,我想用這個東西。嘗試,拋出,捕捉函數
Im做一些功課(實現銀行),我有一個功能
void MoneyMarketing_Account::Transaction_menu()
{
int choice, value;
string login, password;
cout << "Enter name and pas for account ";
cin >> login, password;
cout << "Choose valute and amount" << endl
<< "1 Grn [amount]" << endl
<< "2 Dollars [amount]" << endl
<< "3 Euro [amount]" << endl
<< "4 Forint [amount]" << endl
<< "5 Rub [amount]" << endl;
cin >> choice;
cin >> value;
if(choice == 1)
throw(Request_t(login, password, "Grn", value));
if(choice == 2)
throw(Request_t(login, password, "Dollars", value));
if (choice == 3)
throw(Request_t(login, password, "Euro", value));
if (choice == 4)
throw(Request_t(login, password, "Forint", value));
if (choice == 5)
throw(Request_t(login, password, "Rub", value));
struct Request_t {
string login;
string password;
string type;
int amount;
Request_t(string login_, string password_, string type_, int amount_) {
login = login_;
password = password_;
type = type_;
amount = amount_;
}};
第一個問題是 - 我可以使用throw語句沒有try塊。 第二個就是這個地方會去的地方。例如
void foo()
{
Transaction_menu(); //function that i have shown before
Transaction_catch();//function that is supposed to catch request
}
因此,這是第一個函數將被稱爲第二個輸入?
它看起來像你誤會例外。例外情況不適用於正常流量控制,而是處理「特殊」情況。在這種情況下,它看起來應該'返回'Request_t'? – crashmstr