c++ - Undefined reference when instantiating a class -
this main.cpp. here have problem:
i 2 errors:
undefined reference `bankcontroller::bankcontroller(transactionrepository)* @ line 23
and
undefined reference `transactionfilerepository::transactionfilerepository(std::string) @ line 19
for both of them, type c/c++ problem, resource main.cpp
#include "bankgui.h" #include "controller/bankcontroller.h" #include "repository/transactionfilerepository.h" #include "repository/transactionmemoryrepository.h" #include "repository/transactionrepository.h" #include <qtgui> #include <qapplication> #include <string> #include <iostream> using namespace std; int main(int argc, char *argv[]){ string path = "datastorage/database.txt"; //instantiate main data repository transactionrepository* maindatabase; maindatabase = new transactionfilerepository(path); // <-- error here //instantiate main controller bankcontroller* maincontroller; maincontroller = new bankcontroller(maindatabase); // <-- same error here //starts gui qapplication app(argc, argv); bankgui* mainwidget; mainwidget = new bankgui(maincontroller); mainwidget->show(); return app.exec(); }
i have 3 classes:
a virtual transactionrepository
one class implements above transactionmemoryrepository
one class inherits above transactionmemoryrepository transactionfilerepository
the 3 classes' header files are:
transactionrepository
#ifndef transactionrepository_h_ #define transactionrepository_h_ //--------------------------------------------------------------------------------------------------------------------- #include "../domain/banktransaction.h" #include "../utils/vector.h" #include "../domain/exceptions.h" //--------------------------------------------------------------------------------------------------------------------- class transactionrepository { public: /* * search , return address of transaction matching id */ virtual banktransaction* findbyid(int id) = 0; /* * returns list of transactions */ virtual vector<banktransaction*>findall() = 0; /* * save bank transaction in list */ virtual void save(banktransaction) throw (repositoryexception) = 0; /* * update transaction * */ virtual void update(int id, int day, string type, float amount, string desc) = 0; /* * removes transaction our list */ virtual void remove(int id) = 0; /* * return total number of transactions our list */ virtual void getnr() = 0; /* * copy of list */ virtual void getcopy(vector<banktransaction> list) = 0; virtual ~transactionrepository(){} }; //--------------------------------------------------------------------------------------------------------------------- #endif /* transactionrepository_h_ */ //---------------------------------------------------------------------------------------------------------------------
transactionmemoryrepository
#ifndef transactionmemoryrepository_h_ #define transactionmemoryrepository_h_ #include "transactionrepository.h" #include "../utils/vector.h" class transactionmemoryrepository: public transactionrepository { public: transactionmemoryrepository(); virtual ~transactionmemoryrepository(); /* * search , return address of transaction matching id */ banktransaction* findbyid(int id); /* * returns list of transactions */ vector<banktransaction*>findall(); /* * save bank transaction in list */ void save(banktransaction) throw (repositoryexception); /* * update transaction * */ void update(int id, int day, string type, float amount, string desc); /* * removes transaction our list */ void remove(int id); /* * return total number of transactions our list */ void getnr(); /* * copy of list */ void getcopy(vector<banktransaction> list); protected: vector<banktransaction*> transactionlist; }; #endif /* transactionmemoryrepository_h_ */
transactionfilerepository
#ifndef transactionfilerepository_h_ #define transactionfilerepository_h_ #include <string> #include "../repository/transactionmemoryrepository.h" #include "../utils/vector.h" #include "../domain/banktransaction.h" using namespace std; class transactionfilerepository: public transactionmemoryrepository { private: string filename; vector<banktransaction*> loadfromfile(); void writetofile(); public: transactionfilerepository(string filepath); virtual ~transactionfilerepository(); virtual banktransaction* findbyid(string id); virtual vector<banktransaction*> findall(); virtual void save(banktransaction) throw (repositoryexception); virtual void update(banktransaction) throw (repositoryexception); virtual void remove(string studentid) throw (repositoryexception); }; #endif /* transactionfilerepository_h_ */
the .cpp files last 2 classes (since virtual 1 doesn't require .cpp file) don't have implemented in them. thing added protptypes in (.h)eader files.
i've been searching 2 hours on google solutions try doesn't rid of errors.
i should mention c++ qt project working on. had add project properties include paths things work.
all files included exist.
Comments
Post a Comment