错误:原型for与类中的任何一个都不匹配

时间:2015-12-05 17:51:52

标签: c++

我一直收到这个错误,我看不出有什么问题,我是c ++的新手。

错误是

  

“错误:'void my_payroll :: display_payslip(float,float,float,float)'的原型与'my_payroll'中的任何一个都不匹配|”

以下是代码:

#include <iostream>


class my_payroll
{
public: 
float get_gross(float hours, float rate);
float paye_method (float gross);
float usc_method (float gross);
float prsi(float gross); 
void display_payslip (float gross, float hours, float rate);

`private: 
float dm_hours;
float dm_rate;
float dm_gross;
float dm_paye;
float dm_usc;
float dm_prsi;
float dm_netpay;
};


float my_payroll::get_gross(float hours, float rate)
{
dm_hours = hours;
dm_rate = rate;
return (dm_hours * dm_rate);
}

float my_payroll::paye_method(float gross)
{
dm_gross = gross;
if (dm_gross <= 630.77)
{dm_paye = dm_gross * .2;}
if (dm_gross > 630.77)
{dm_paye = ((dm_gross - 630.77) * 41) + 126.15;}
return dm_paye;
}

float my_payroll::usc_method(float gross)
{
dm_gross = gross;
if (dm_gross <= 193)
{dm_usc = dm_gross * .02;}
if (dm_gross > 308)
{dm_usc = ((dm_gross - 308) *.07) +8.46;}
if (dm_gross > 193 && dm_gross <= 308)
{dm_usc = ((dm_gross - 193) *04) + 3.86;}
return dm_usc;

}    
float my_payroll::prsi(float gross)
{
dm_gross = gross;
dm_prsi = (dm_gross * .02 ); 
return dm_prsi;
}


void my_payroll::display_payslip(float gross, float hours, float rate, float              netpay) > this is the line that I'm getting the error on
{
dm_hours = hours;
dm_netpay = netpay;
dm_rate = rate;
dm_gross = gross;
dm_netpay = (dm_gross - dm_usc - dm_paye - dm_prsi);
return;
cout << "*****************************" << endl;
cout << "\t Gross Pay " << gross<< endl;
cout << "\t prsi " << prsi << endl;
cout << "\t paye " << paye<< endl;
cout << "\t usc " << usc << endl;
cout << "\t Net " << netpay << endl;
cout << "*****************************" << endl;

}





float hours, rate;
float gross;
float paye;
float usc;
float prsi;
float netpay;


int main()

{
cout << "Key in hours worked "  << endl;
cin >> hours;
cout << "Key in hourly rate " << endl;
cin >> rate;
]

class my_payroll payroll_object;

gross = payroll_object.get_gross(hours,rate);
paye = payroll_object.paye_method(gross);
usc = payroll_object.usc_method(gross);
prsi = payroll_object.prsi(gross);
payroll_object.display_payslip(gross);

1 个答案:

答案 0 :(得分:1)

在类定义中,声明的成员函数display_payslip有三个参数

void display_payslip (float gross, float hours, float rate);

但是,您尝试使用四个参数定义具有相同名称的函数

void my_payroll::display_payslip(float gross, float hours, float rate, float              netpay) > this is the line that I'm getting the error on
{
//...

因此编译器会发出错误。