2014-09-05 75 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

相关问题