Undefined reference to

For some reason, every time I try to construct an array from my Vector class, I keep getting error messages

|7|undefined reference to `Vector<int>::Vector(int, int const&)'
|8|undefined reference to `Vector<int>::~Vector()'

main.cpp
1
2
3
4
5
6
7
8
9
#include <iostream>
#include "Vector.h"

using namespace std;

int main(){
Vector<int> testvec(5,13);
    return 0;
}


Vector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef VECTOR_H
#define VECTOR_H

template <class T>
class Vector{
    private:
        T arr[];
    public:
        Vector();
        Vector(int n, const T& val);
        Vector(const Vector<T>& v);

        virtual ~Vector();

        unsigned int size();
        void push_back(const T&);
        void pop_back();
        T& at(int);

    protected:
};

#endif // VECTOR_H 


Vector.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Vector.h"
//Constructors
template <class T>
Vector<T>::Vector(){
    arr [0];
}

template <class T>
Vector<T>::Vector(int n, const T& val){
    T arr [n];
    for(int i = 0; i<n; i++){
        arr[i] = val;
    }
}

template <class T>
Vector<T>::Vector(const Vector<T>& v){
    arr = v;
}

//Deconstructor
template <class T>
Vector<T>::~Vector(){
    delete arr;
}

//Methods
//Size will get the size of the array
template <class T>
unsigned int Vector<T>::size(){
int total;
    while(arr){
        total++;
    }
return total;
}

//Push_back will add a value to the end
template <class T>
void Vector<T>::push_back(const T& elt){
    int nelts, index = 0;
    //Acquire size
    nelts = arr.size();
    //We need a temp copy
    T temp[nelts];
    while(arr){
    temp[index] = arr[index];
    index++;
    }
    //We change the array
    index = 0;
    T *arr = new Vector[nelts+1];
    while(temp){
        arr[index] = temp[index];
        index++;
    }
    //Add the last value
    arr[index] = elt;
}

//Pop_back will delete the last value
template <class T>
void Vector<T>::pop_back(){
    int nelts, index = 0;
    //Acquire size
    nelts = arr.size();
    //We need a temp copy
    T temp[nelts];
    while(arr){
    temp[index] = arr[index];
    index++;
    }
    //We change the array
    index = 0;
    T *arr = new Vector[nelts-1];
    while(arr){
        arr[index] = temp[index];
        index++;
    }
}

//Pop_back will delete the last value
template <class T>
T& Vector<T>::at(int pos){
    return &arr[pos];
}


I'm trying to construct an array with 5 copies of 13.
You cannot (non-trivially) place template implementations in source files. They should go into header too.
Topic archived. No new replies allowed.