Why is it that every time I try to run my code, I get the following problem?
g++ -Wall -fexceptions -g -Iinclude -c /Users/Soul/Documents/School/Program1/main.cpp -o obj/Debug/main.o
g++ -o bin/Debug/Program1 obj/Debug/main.o obj/Debug/src/Vector.o
Undefined symbols for architecture x86_64:
"Vector<int>::Vector(int, int const&)", referenced from:
_main in main.o
"Vector<int>::~Vector()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The constructor doesn't seem to work for some reason.
main.cpp
1 2 3 4 5 6 7 8 9 10 11
|
#include <iostream>
#include "Vector.h"
using namespace std;
int main(){
Vector<int> testvec(4,5);
delete testvec.data_val;
return 0;
}
|
Vector.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#ifndef VECTOR_H
#define VECTOR_H
template <class T>
class Vector{
public:
T *data_val;
Vector();
Vector(int n,const T& val);
Vector(const Vector& other);
virtual ~Vector();
protected:
private:
};
#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
|
#include "Vector.h"
template <class T>
Vector<T>::Vector(){
data_val = new T[0];
}
template <class T>
Vector<T>::Vector(int n,const T& val){
data_val = new T[n];
for(int index = 0; index < n; index++)
data_val[index];
}
template <class T>
Vector<T>::Vector(const Vector& other){
//copy ctor
}
template <class T>
Vector<T>::~Vector(){
delete data_val;
}
|