I decided to write my own Vector class for my library but when I try to compile it using g++ -Wall -std=c++11 -O a.cpp -c -o a.o
and read the symbols from the output file using nm a.o
I don't see any member functions that I wrote for that class and when I try to link it with a program that uses them I get undefined reference to
errors.
Here is the a.h file:
template<typename T> class Vector {
private:
int vsize;
const int maxsize=2147483647;
T* array;
public:
Vector();
~Vector();
bool push_back(T t);
bool pop_back(T* t);
bool replace(int element, T t);
bool resize(int newsize);
bool getP(int element, T* t);
bool clear();
T* getArray();
int size();
T operator[](int n);
};
And the a.cpp file:
#include <stdlib.h>
#include "a.h"
template<typename T> Vector<T>::Vector() {
vsize=0;
array=(T*)malloc(sizeof(T)*vsize);
}
template<typename T> Vector<T>::~Vector() {
free(array);
}
template<typename T> bool Vector<T>::push_back(T t) {
if(resize(vsize+1))
return 1;
array[vsize-1] = t;
return 0;
}
template<typename T> bool Vector<T>::pop_back(T* t) {
*t = array[vsize-1];
return resize(vsize-1);
}
/*
Other member function definitons...
*/
I'm using g++ 5.4.0 and nm 2.26.1