gpt4 book ai didi

c++ - 无法找到未解析的外部符号 (c++)

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:25:10 24 4
gpt4 key购买 nike

做类作业。收到此错误消息:

    1>------ Build started: Project: Mulvihill_Program_7, Configuration: Debug Win32 ------
1>Mulvihill_Program_7.obj : error LNK2019: unresolved external symbol "double __cdecl calcGross(void)" (?calcGross@@YANXZ) referenced in function _main
1>c:\users\pat\documents\visual studio 2012\Projects\Mulvihill_Program_7\Debug\Mulvihill_Program_7.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

代码如下:

#include<iostream>
using namespace std;

int getHoursWorked();
double getPayRate();
double calcGross();

int hoursWorked = 0;
double payRate = 0.0;
double grossPay = 0.0;
double OVERTIME = 1.5;
double overTimePayRate = 0.0;
double pay = 0.0;



int main()
{

getHoursWorked();
getPayRate();
pay = calcGross();

cout<<pay;
}

int getHoursWorked()
{
cout<<"Enter the amount of hours worked ";
cin>>hoursWorked;

return(hoursWorked);
}

double getPayRate()
{
cout<<"How much do you make an hour? ";
cin>>payRate;

return(payRate);

}

double calcGross(int hoursWorked, double payRate)
{
if (payRate < 40)
{
grossPay = hoursWorked * payRate;
}
else
{
overTimePayRate = OVERTIME * payRate;
grossPay = hoursWorked * overTimePayRate;
}
return(grossPay);
}

我知道这段代码可能有很多错误,而不仅仅是约定等方面的错误,但我是新手,我现在只是想了解错误消息。

最佳答案

链接器找不到这个函数定义,

double calcGross();

因为你这样定义函数,

double calcGross(int hoursWorked, double payRate)

是否应该删除参数以便函数声明和定义匹配。像这样更改您的函数声明,

int getHoursWorked();
double getPayRate();
double calcGross(int hoursWorked, double payRate);

然后在main()中调用时传递hoursWorked & payRate的值

关于c++ - 无法找到未解析的外部符号 (c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20485883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com