So im working on an assignment for school and i keep on getting an error that says: undefined reference to vtable.
I already tried defining all my virtual function. I have tried multiple things such as virtual destructor, defining all virtual functions and what not. If someone could please explain whats wrong with my code, i would greatly appreciate it. I am using multiple files as well. the screenLogger.h file is the one that is giving me issues. When i fix them, i will get issues in screenLogger.cpp..... when i fix them, then the singleton class gives me errors.....
************CS1337Logger.cpp file******************************
# include <iostream>
# include "CS1337Logger.h"
// Set LoggerEnabled value
void CS1337Logger::setLogging(bool x)
{
loggingEnabled = x ;
}
//virtual function. Makes class pure virtual (abstract)
virtual void displayMessage(const char* ) = 0;
//constructor
CS1337Logger();
//destructor
virtual ~CS1337Logger();
};
#endif /* CS1337LOGGER_H_ */
**********FileLogger.cpp file**************************************
# include <iostream>
# include "FileLogger.h"
using namespace std;
//Define displayMessage function
void FileLogger::displayMessage(const char* x)
{
logName << x << endl ;
}
//constructor
FileLogger::FileLogger()
{
logName.open("Log.txt"); // open the file to write to.
if( !logName ) // code segment for file being read. if file doesn't open do:
{
cout << "\nLog file was NOT opened successfully. Terminating program. " ; //Error Message
logName.close(); // close input file
exit(EXIT_FAILURE); // Error Code : 1 means file was not opened successfully
}
}
#include "LogSingleton.h"
#include <iostream>
using namespace std ;
//allocate memory for static variable
CS1337Logger *LogSingleton::GetLogger = 0 ;
//define getLogger method. Check that only one instance of the logger exists
CS1337Logger* LogSingleton::getLogger()
{
if(GetLogger == NULL ) // if instance doesnt exist, create one.
{
//LogSingleton::GetLogger = new FileLogger (); //to log in files uncomment
GetLogger = new ScreenLogger (); // to log in console uncomment
}
return GetLogger ; // return my instance
}
***main.cpp file********************************************************
//This is just a test driver. just wanna make sure things work well.
Try uncommenting ScreenLogger's ctor and dtor. I know you've probably already tried that. But do it, run it that way, and post that version along with the entire, exact (copy/pasted) error message.
Post the code in code tags:
[code]
your code goes here
maintains indentation
adds syntax highlighting
lowers cholesterol [/code]
And if you expect people to be able to run it, a link to a zip file would be nice (just the .cpp and .h files).