I Created a Test.h and Test.cpp in Visual Studio.
Test.h
#ifndef TEST_H
#define TEST_H
class Test {
public:
Test(int num);
int getMyNum();
private:
int myNum = 0;
};
#endif // !TEST_H
Test.cpp
#include "Test.h"
Test::Test(int num) {
myNum = num;
}
int Test::getMyNum()
{
return myNum;
}
So when I want to use the Test
class in other project in Visual Studio I can just go to project properties >> VC++ Directories >> Include Directories, and then paste the path to the files location.
And in this project I create a main.cpp
#include <iostream>
#include <Test.h>
int main(){
Test test(4);
std::cout << test.getMyNum();
}
I thought it should work just fine, and it do not give me any errors, but when I try to compile it I get some unresolved external symbol errors:
unresolved external symbol "public: __cdecl Test::Test(int)" (??0Test@@QEAA@H@Z) referenced in function main
unresolved external symbol "public: int __cdecl Test::getMyNum(void)" (?getMyNum@Test@@QEAAHXZ) referenced in function main
It do not look like there is any symbol without definition.
What I wanted to know is why this is happening, and how to solve it.