I'm pretty new to C++ and we're working with linked lists and classes. I have my program mostly working but my voidCalc function is giving me the error of:
error LNK2019:
unresolved external symbol "void __cdecl calcData(class WeatherStats * const,int)"
(?calcData@@YAXQAVWeatherStats@@H@Z)
referenced in function _main
I'm only including the main file, if you need the headers for the other two I can add them. Thank you!!
#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";
}
}
Your function prototype is:
void calcData (WeatherStats stats[], int SIZE);
Your function declaration is:
void calcData (WeatherStats *stats[], int SIZE) { ... }
Those are not the same.
Try declaring the calcData
function like this:
void calcData (WeatherStats *stats[], int SIZE);
or this:
extern "C" void calcData (WeatherStats *stats[], int SIZE);
(Please note the extra star added.)
If this doesn't help, make sure to include the library ( .lib
or .dll
) defining this function in your linker command line (or in the dependency list in the IDE project settings).
You have a discrepancy with your function prototype and your actual function.
void calcData (WeatherStats stats[], int SIZE);
void calcData (WeatherStats *stats[], int SIZE);
Notice that you have a * in the actual function signature and none in the prototype.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.