I am fairly new to C++. I tried to create a library with a few functions and classes.
In the visual studio solution, I created another console project, included the library, it worked for the first few times, but as I created more source files, the linker gives me LNK 2019 errors of unresolved external symbols.
I have implemented all the functions in my header files and classes, what possibly could go wrong? Here is my includes
TS.h
/* I include "TS.h" in the console project */
#pragma once
#include "TMiscFunc.h"
#include "TFraction.h"
TFraction.h
#pragma once
#include <iostream>
#include "TMiscFunc.h"
namespace TS {
//The class which simulates a fraction
}
TFraction.cpp
#include "TFraction.h"
//Implementation of the functions of TFraction.h
TMiscFunc.h
namespace TS {
template <typename T0> T0 TAbsolute(T0 value);
template <typename T0> T0 TCeiling(T0 value);
template <typename T0> T0 TFloor(T0 value);
template <typename T0> T0 TPower(T0 value, int power);
TMiscFunc.cpp
#include "TMiscFunc.h"
template <typename T0> T0 TAbsolute(T0 value) {
//operations...
}
template <typename T0> T0 TCeiling(T0 value) {
//operations...
}
template <typename T0> T0 TFloor(T0 value) {
//operations...
}
template <typename T0> T0 TPower(T0 value, int power) {
//operations...
}
The error messages:
Error LNK2019 unresolved external symbol "int __cdecl
TS::TAbsolute<int>(int)" (??$TAbsolute@H@TS@@YAHH@Z)
referenced in function "public: void __thiscall
TS::TFraction::Simplify(void)" (?
Simplify@TFraction@TS@@QAEXXZ)
All the errors are the same except the function names are changed
Thank you all for reading.
//It is solved