2014-09-05 78 views
-1

的成員我已經聲明瞭我的函數'Credit'作爲一個私有成員的一些參數。我的觀察是,只要我嘗試編譯沒有任何參數,編譯器就會成功編譯。但只要我編譯的函數的參數,編譯器會給出錯誤<function>不是<class>

「交易信用::」不是「交易」

這裏的一員是我的代碼

class Transaction : public Menu 
{ 
private : 

    void Credit(int depost);//{ return 0;} 

public : 
    void Deposit(); 
    void Withdraw(){} 
    void Transfer(){} 
}; 

void Transaction :: Deposit() 
{ 
     char custid[10]; int deposit; 

     clrscr(); 
     cout << endl << endl << endl << endl << endl; 
     cout << "\t\t\t\t DEPOSIT " << endl; 
     cout << "\t\t Please enter your Customer ID" << endl; 
     cin >> custid; 
     cout << "\t\t Please enter the amount you want to deposit (in Rupees)" << endl; 
     cin >> deposit; 

//  Credit (depost); 
} 

void Transaction :: Credit (depost) 
{ 

} 

我正在使用Turbo C++,因此請根據此IDE指導我。

+1

定義'void Transaction :: Credit(depost)'應該有'depost'的類型說明符,即 'void Transaction :: Credit(int depost)' – YoungJohn 2014-09-05 20:58:19

+0

就是這樣!謝謝。但爲什麼我們需要一個類型說明符? @YoungJohn – Swanav 2014-09-05 21:01:50

+0

@Swanav:你爲什麼不呢? C++是一個強大的(無論如何...),靜態類型的語言。 – 2014-09-05 21:04:33

回答

1

你錯過depost類型:

void Transaction :: Credit (int depost) 

而且它被認爲是不好的做法,以大寫字母開頭的函數的名稱。類的名字應該以大寫字母開頭。函數和變量應該具有以小寫字母開頭的名稱。

+2

大寫字母的命名功能並不是不好的做法。這只是一個意見。引用Google樣式表[這裏](https://google.github.io/styleguide/cppguide.html#Function_Names): 「通常,函數應該以大寫字母開頭並且每個新單詞都有大寫字母」 – niosus 2017-02-09 11:25:33

+0

Downvote是因爲當你完全主觀的時候強迫你對命名約定的意見。刪除最後一點,我會刪除我的downvote。 – CodingMadeEasy 2017-05-04 14:49:34

相關問題