jeudi 22 octobre 2020

Undefined reference to class constructor h files

I've multiple classes for a program and I've fixed all the errors, but when I try to compile, it is now showing undefined reference to `event::event(std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, int, int)'

I'm new to cpp and not able to make sense of what's happening here. The same error is also being reported for other classes. Could it be something is wrong in the h files. I'm pasting one below, can someone tell me how to fix this.

#ifndef EVENT_H
#define EVENT_H

#include <string>
#include <iostream>
#include <iomanip>

class event
{
protected:
    std::string location, uniqueFeature;
    double uniFeaFactorT, uniFeaFactorF;

public:
    event(std::string location = "", std::string uniqueFeature = "", int uniFeaFactorT = 0, int uniFeaFactorF = 0);
    double getUFF(bool f);
    std::string getLoc();
    std::string getUF();
};

double event::getUFF(bool f){ return (f) ? uniFeaFactorT : uniFeaFactorF;}

std::string event::getLoc(){ return location;}

std::string event::getUF(){ return uniqueFeature;}

static std::ostream &operator<<(std::ostream &out, event &e)
{
    out << "City: " << e.getLoc() << "\nUnique Feature: " << e.getUF();
}

#endif

The objects are being made in the main function by reading from a file. I'm also pasting the file reading code below:

std::ifstream fin1(eventFileNm);
std::string lineV;
std::vector<string> v;
while (getline(fin1, lineV))
{
    std::istringstream iss(lineV);
    std::string fieldV;
    while (getline(iss, fieldV, ';'))
    {
        v.push_back(fieldV);
    }

    event *b = new event(v[0], v[1], stoi(v[2]), stoi(v[3]));
    eventvec.push_back(b);
}

The eventvec vector is declared as a parameter in the function.

Aucun commentaire:

Enregistrer un commentaire