I have logger class with singleton instance and main function
// Logger.h
class Logger
{
public:
enum LogLevel { ALL, INFO, WARNING, ERROR, NEEDED };
static std::shared_ptr<Logger> getInstance()
{
if (instance == 0)
{
instance.reset(new Logger());
}
return instance;
}
Logger(LogLevel level=LogLevel::WARNING)
{
Errorlevel = level;
if (Errorlevel <= INFO)
{
cout << "[" << LogLevelNames[Errorlevel] << "]: " << "LOGGER set to: " << LogLevelNames[Errorlevel] << std::endl;
}
}
~Logger(){}
private:
LogLevel Errorlevel = ALL;
string LogLevelNames[5] = { "ALL","INFO","WARNING", "ERROR", "NEEDED" };
static std::shared_ptr<Logger> instance;
};
using above Logger singleton in main function
// main.cpp
int main(int argc, char **argv)
{
std::shared_ptr<Logger> logger = std::make_shared<Logger> (Logger::LogLevel::WARNING);
if(ip_address == "UNKNOWN" && admin == "UNKNOWN")
{
logger->log(Logger::ERROR, "Check config for cam_ip_address or cam_admin");
return (0);
}
}
Getting following error:
main.cpp:(.text._ZN5CFaceC2ESt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EES6_[_ZN5CFaceC5ESt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EES6_]+0x166): undefined reference to `Logger::instance'
how to resolve this issue ?
Aucun commentaire:
Enregistrer un commentaire