Pierwszy raz tworzę klasę z wykorzystaniem template. Jest to klasa wektor. Mogły mi ktoś wskazać co robię zle?
wektor.h
#pragma once
#include <string>
template < class T >
class Wektor
{
T *s; int rozmiar;
public:
Wektor();
void push(T x);
int size();
~Wektor();
};
wektor.cpp
#include "Wektor.h"
template <class T>
Wektor<T>::Wektor():s(nullptr), rozmiar(0)
{}
template<class T>
void Wektor<T>::push(T x)
{
delete s;
s = new T[rozmiar + 1];
rozmiar++;
}
template<class T>
int Wektor<T>::size()
{
return rozmiar;
}
template<class T>
Wektor<T>::~Wektor()
{
delete s;
}
main.cpp
Wektor<int> x;
return 0;
Bład który wyskakuje:
Error LNK2019 unresolved external symbol "public: __thiscall Wektor<int>::~Wektor<int>(void)" (??1?$Wektor@H@@QAE@XZ) referenced in function _main
Robisz delete nie sprawdzając wskaźnika;
-In all cases, if ptr is a null pointer, the standard library deallocation functions do nothing
(http://en.cppreference.com/w/cpp/memory/new/operator_delete)