【问题标题】:C++ Problem: [Error] statement cannot resolve address of overloaded function x2C++ 问题:[Error] 语句无法解析重载函数 x2 的地址
【发布时间】:2021-06-30 16:40:40
【问题描述】:

我完全是个菜鸟,需要帮助。希望比我有经验的各位大侠能帮帮我。

非常感谢任何输入。

由于代码太长,代码应该是这样的:

#include <iostream>
    
    using namespace std;
    
    class Payslip
    {
    
    string name, pay_grade;
    float salary, oth, otp, gross, net, tax, sss, pagibig, philhealth;
    
    public: 
    void payslipdetails()
    {
    
    // Extremely long, but this part of the code would allow me to allow user to input their names, their base salary, and overtime hours.
    
    sss = 500;
    pagibig = 200;
    philhealth = 100;
    otp = oth * (salary*0.01);
    gross = salary + otp;
    net = gross - (tax + sss + pagibig + philhealth);
    
    // then a series of if/else if condition if salary is greater/less than or equals to, and we divide the said salaries into pay grade A or B. 

/* Example: 
                if (salary >= 10000 && salary <= 19999)
                {
                    // Pay grade A
                    if (salary >= 10000 && salary <= 14999) 
                    {
                    pay_grade = "A";
                    }
                    
                        // Pay grade B
                        else if (salary >= 15000 && salary <= 19999)
                        {
                            pay_grade = "B";
                        }
                    tax = gross * 0.10;
                }*/
                
    
    }
    }
    
    void display_details()
    {
    cout<<"\n Employee Name              : " << name;
                    cout<<"\n Basic Salary               : " << salary;
                    cout<<"\n Pay Grade                  : " << pay_grade;
                    cout<<"\n No. of OT hours            : " << oth;
                    cout<<"\n OT Pay                     : " << otp;
                    cout<<"\n Gross Pay                  : " << gross;
                    cout<<"\n Withholding Tax            : " << tax;
                    cout<<"\n Net Pay                    : " << net;
            }
    };
    int main()
    {
            Payslip d;
            d.payslipdetails;
            d.display_details;
            return 0;
    }

d.payslipdetails 和 d.displaydetails 中有错误。我希望这比我上一篇文章更清楚!

错误是:[错误]语句无法解析重载函数的地址

我不知道该怎么做...

【问题讨论】:

  • 请提供minimal reproducible examplePayslip 是什么?
  • 如果您不告诉我们错误是什么,我们无法帮助您...
  • 如果您打算调用这两个函数,则缺少 () 括号。
  • 没有它们,表达式只能被评估为一个(丢弃的)函数指针,但由于它们被重载,编译器无法选择一个唯一的。因此出现错误消息。
  • 永远不要将代码作为图片发布!请访问Welcome tourhelp center

标签: c++


【解决方案1】:

您是否可能尝试调用对象d 的方法?然后,您至少需要添加括号。至于每个函数调用:

    d.payslipdetails();

【讨论】:

    【解决方案2】:

    检查方法名称 paySlipDetails();根据 Payslip 类的实现代码提供任何所需的参数。

    【讨论】:

      猜你喜欢
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      相关资源
      最近更新 更多