I'm working through an intro video series on cpp and I'm running into a linker error, but I'm not sure why I'm hitting it.
I'm def still green to reading complier and linker errors so this may be wrong, but it seems like the linker is telling me that I haven't defined the methods that I'm calling in my main function. It makes me suspect that I have something wrong in my header file. Here's the current state of my files:
main.cpp
#include "Log.h"
int main() {
Log log;
log.SetLevel(Log::LevelError);
log.Warn("hello from main");
log.Error("hello from main");
log.Info("hello from main");
}
Log.h
#pragma once
class Log {
public: // variables
enum Level {
LevelError, LevelWarning, LevelInfo
};
public: // methods
void SetLevel(Level level);
void Error(const char* message);
void Warn(const char* message);
void Info(const char* message);
};
Log.cpp
#include <iostream>
class Log {
public: // variables
enum Level {
LevelError, LevelWarning, LevelInfo
};
private: // variables
Level m_LogLevel = LevelWarning;
public: // methods
void SetLevel(Level level){
m_LogLevel = level;
}
void Error(const char* message){
if (m_LogLevel >= LevelError)
std::cout << "[ERROR]: " << message << std::endl;
}
void Warn(const char* message){
if (m_LogLevel >= LevelWarning)
std::cout << "[WARNING]: " << message << std::endl;
}
void Info(const char* message){
if (m_LogLevel >= LevelInfo)
std::cout << "[Info]: " << message << std::endl;
}
};
In the video series I'm watching the instructor defined the log class within the main.cpp file, but I wanted to try to start organizing my files by moving the log class out to it's own file and pulling it in via a header file.
I tried to figure out what I'm doing wrong by searching around on the internet, but whether it's because I can't find the exact problem I'm hitting or I'm just still to green to cpp to see the solution in the answers I'm finding I can't seem to figure it out.
Can someone point me in the right direction, please??