I am trying to create a simple array program. While I was testing member function Size() I am getting LNK2019 and LNK1120 error.
arr.h
#pragma once
namespace PV
{
template <typename T, int S>
class Array
{
public:
int Size();
private:
T array[S] = { 0 };
};
}
arr.cpp
#include "arr.h"
template<typename T, int S>
inline int PV::Array<T, S>::Size()
{
return S;
}
driver.cpp
#include<iostream>
#include"arr.h"
int main()
{
PV::Array<int, 5> arr;
std::cout << arr.Size();
}
ERROR =
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: int __thiscall PV::Array<int,5>::Size(void)" (?Size@?$Array@H$04@PV@@QAEHXZ) referenced in function _main PV_TemplateLibrary C:\Users\Fireworks\Documents\PV_TemplateLibrary\driver.obj 1
Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals PV_TemplateLibrary C:\Users\Fireworks\Documents\PV_TemplateLibrary\Debug\PV_TemplateLibrary.exe
1
I am using Visual Studio 2022.