我对C ++很陌生,我们正在使用链表和类。我的程序主要工作,但我的voidCalc函数给出了错误:
error LNK2019:
unresolved external symbol "void __cdecl calcData(class WeatherStats * const,int)"
(?calcData@@YAXQAVWeatherStats@@H@Z)
referenced in function _main
我只包含主文件,如果你需要其他两个标题,我可以添加它们。谢谢!!
#include "LinkedList.h"
#include "WeatherStats.h"
#include <iostream>
#include <iomanip>
using namespace std;
//Function prototype for highest/lowest
void calcData (WeatherStats stats[], int SIZE);
int main()
{
LinkedList<WeatherStats> weather;
WeatherStats stats;
double rain, snow;
int sun, months;
cout << "Please enter the number of months you would like to report on.\n";
cin >> months;
stats.setMonths(months);
for(int count = 0; count < months; count++)
{
//Get the information from the user
stats.setMonths(count+1);
cout << "Please enter the amount of snow for month " << (count+1) << endl;
cin >> snow;
stats.setSnow(snow);
cout << "Please enter the amount of rain for month " << (count+1) << endl;
cin >> rain;
stats.setRain(rain);
cout << "Please enter the amount of sunny days for month " << (count+1) << endl;
cin >> sun;
stats.setSun(sun);
cout << endl;
//Add the node
weather.appendNode(stats);
}
weather.displayList();
calcData(&stats, months);
return 0;
}
void calcData (WeatherStats *stats[], int SIZE)
{
int highSun = 0;
int highSunMonth, lowSunMonth, highRainMonth, lowRainMonth, highSnowMonth, lowSnowMonth;
int lowSun = 0;
double lowRain = 0;
double highRain = 0;
double lowSnow = 0;
double highSnow = 0;
for (int count = 1; count <= SIZE; count++)
{
//Highest Sun and its month
if(highSun < stats[count]->getSun())
{ highSun = stats[count]->getSun();
highSunMonth = stats[count]->getMonths();
}
//Lowest sun and its month
if (lowSun > stats[count]->getSun())
{ lowSun = stats[count]->getSun();
lowSunMonth = stats[count]->getMonths();
}
//Highest rain and its month
if(highRain < stats[count]->getRain())
{
highRain = stats[count]->getRain();
highRainMonth = stats[count]->getMonths();
}
//Lowest rain and its month
if (lowRain > stats[count]->getRain())
{
lowRain = stats[count]->getRain();
lowRainMonth = stats[count]->getMonths();
}
//Highest snow and its month
if (highSnow < stats[count]->getSnow())
{
highSnow = stats[count]->getSnow();
highSnowMonth = stats[count]->getMonths();
}
//Lowest snow and its month
if (lowSnow > stats[count]->getSnow())
{
lowSnow = stats[count]->getSnow();
lowSnowMonth = stats[count]->getMonths();
}
//Output findings
cout << "The month with the most sun was Month " << highSunMonth << " with " << highSun << " days.\n";
cout << "The month with the least sun was Month " << lowSunMonth << " with " << lowSun << " days.\n";
cout << "The month with the most rain was Month " << highRainMonth << " with " << highRain << " units.\n";
cout << "The month with the least rain was Month " << lowRainMonth << " with " << lowRain << " units.\n";
cout << "The month with the most snow was Month " << highSnowMonth << " with " << highSnow << " units.\n";
cout << "The month with the least snow was Month " << lowSnowMonth << " with " << lowSnow << " units.\n";
}
}
答案 0 :(得分:3)
您的函数原型是:
void calcData (WeatherStats stats[], int SIZE);
您的功能声明是:
void calcData (WeatherStats *stats[], int SIZE) { ... }
那些不一样。
答案 1 :(得分:0)
尝试像这样声明calcData
函数:
void calcData (WeatherStats *stats[], int SIZE);
或者这个:
extern "C" void calcData (WeatherStats *stats[], int SIZE);
(请注意添加额外的明星。)
如果这没有帮助,请确保在链接器命令行(或IDE项目设置的依赖项列表)中包含定义此函数的库(.lib
或.dll
)。
答案 2 :(得分:0)
您的功能原型和实际功能存在差异。
void calcData (WeatherStats stats[], int SIZE);
void calcData (WeatherStats *stats[], int SIZE);
请注意,实际的函数签名中有*,原型中没有。