This error has been reported many times but I couldn't find what I was looking for. The following are the build errors
error LNK2019: unresolved external symbol "public: enum CLASS_ID __thiscall smp::sampleAbs::getClassID(void)" (?getClassID@sampleAbs@smp@@QAE?AW4CLASS_ID@@XZ) referenced in function "public: virtual void __thiscall mockSmp::run(void)" (?run@mockSmp@@UAEXXZ)
error LNK2001: unresolved external symbol "public: enum CLASS_ID __thiscall smp::sampleAbs::getClassID(void)" (?getClassID@sampleAbs@smp@@QAE?AW4CLASS_ID@@XZ)
error LNK2019: unresolved external symbol "public: __thiscall smp::sampleAbs::sampleAbs(enum CLASS_ID)" (??sampleAbs@smp@@QAE@W4CLASS_ID@@@Z) referenced in function "public: __thiscall mockSmp::mockSmp(void)" (??0mockSmp@@QAE@XZ)
And this is my code.
sampleAbs.h
typedef enum
{
//sample enum values
}CLASS_ID;
namespace smp {
class sampleAbs
{
public:
sampleAbs(CLASS_ID classID);
~sampleAbs(void) {}
CLASS_ID getClassID(void);
virtual void run() = 0;
private:
CLASS_ID m_classId;
};
}
sampleAbs.cpp
#include "sampleAbs.h"
namespace smp {
sampleAbs :: sampleAbs(CLASS_ID classID)
{
m_classID = classID;
}
CLASS_ID
sampleAbs:: getClassID(void)
{
return m_classID;
}
}
mock_sampleAbs.h
#include "sampleAbs.h"
using namespace smp
class mockSmp : public sampleAbs
{
public:
CLASS_ID m_classID = 1;
mockSmp() : sampleAbs(m_classID){}
~mockSmp();
void run()
{
m_classID = getClassID();
}
};
test.cpp
#include "mock_sampleAbs.h"
#include "gtest/gtest.h"
using namespace cmd;
TEST(test_getCommandID00, FunctionCoverage)
{
mockSmp mObj;
mObj.run();
EXPECT_EQ(1, mObj.m_commandID);
}
I am not sure what I'm doing wrong, possibly something stupid. Would appreciate any help. Thank you!