-3

I was just trying to see if I can read a text file and display but I have this error:

2 error LNK2019: unresolved external symbol "public: void __thiscall WeatherReport::displayReport(void)" (?displayReport@WeatherReport@@QAEXXZ) referenced in function _main

Can anyone explain me what is causing this, why this is happening and how to fix this problem?

    #include<fstream>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<iostream>

    using namespace std;

    class WeatherReport
    {
        WeatherReport friend monthEnd(WeatherReport, WeatherReport);
        private:
            int dayofMonth;
            int highTemp;
            int lowTemp;
            double amoutRain;
            double amoutSnow;

        public:
            WeatherReport(int Day = 0);
            void setValues(int, int, int, double, double);
            void getValues();
            void displayReport();
    }
    void WeatherReport::setValues(int dom, int ht, int lt, double ar, double as)
    {
        dayofMonth = dom;
        highTemp = ht;
        lowTemp = lt;
        amoutRain = ar;
        amoutSnow = as;
    }

    int main()
    {
        const int DAYS = 30;
        WeatherReport day[DAYS];
        WeatherReport summary;
        int i = 0;

        ifstream inFile;
        inFile.open("WeatherTest.txt");
        if (!inFile)
            cout << "File not opended!" << endl;
        else
        {
            int dom, ht, lt; 
            double ar, as;
            while (inFile >> dom >> ht >> lt >> ar >> as)
            {
                day[i].setValues(dom, ht, lt, ar, as);
                i++;
            }
        inFile.close();

        for (int i = 0; i < DAYS; i++)
        {
            day[i].displayReport();
            //read one line of data from the file
            //pass the data to setValues to initialize the object
        }
        system("PAUSE");
        return 0;
    }
jpw
  • 44,361
  • 6
  • 66
  • 86
Meene
  • 3
  • 1

3 Answers3

0

The error speaks for itself

LNK2019: unresolved external symbol "public: void __thiscall WeatherReport::displayReport(void)

It can't find the definition for WeatherReport::displayReport(). I see its declaration in your code, but there's no definition anywhere. Either you didn't write a definition, or you provided it and didn't link the .cpp file that it's in. I'm guessing the former.

Barry
  • 286,269
  • 29
  • 621
  • 977
0

Seems like displayReport() does not have a body - it is only declared, but not defined. Add the following:

void WeatherReport::displayReport()
{
  //your code
}
hernyo
  • 48
  • 4
0

Your displayReport does not have a function body, and as such does not have an external symbol referencing it, hence the error. Add a function body for displayReport, and the issue will go away:

void WeatherReport::displayReport()
{
  //Place your code here.
}

The following code can be used to reproduce this error:

[header file- test.h]:

#include "StdAfx.h"

void someOtherFunction();
void someFunction(string thisVar);

[code file- test.cpp]:

#include "StdAfx.h"
#include "test.h"

void someOtherFunction()
{
    printf("Hello World!");
}

[function body for someFunction(string thisVar) is missing!]

AStopher
  • 4,207
  • 11
  • 50
  • 75