C++ HELP
I get these errors when I try to compile the main file.
/tmp/cc8VVSeG.o(.text+0x122): In function `main': : undefined reference to `TemperatureList::TemperatureList(int)' /tmp/cc8VVSeG.o(.text+0x13d): In function `main': : undefined reference to `TemperatureList::add_temperature(double)' /tmp/cc8VVSeG.o(.text+0x158): In function `main': : undefined reference to `TemperatureList::add_temperature(double)' /tmp/cc8VVSeG.o(.text+0x173): In function `main': : undefined reference to `TemperatureList::add_temperature(double)' /tmp/cc8VVSeG.o(.text+0x18e): In function `main': : undefined reference to `TemperatureList::add_temperature(double)' /tmp/cc8VVSeG.o(.text+0x1a8): In function `main': : undefined reference to `TemperatureList::get_last() const' collect2: ld returned 1 exit status
THIS IS THE CODE IN THREE DIFFERENT FILES:
templist.h
#ifndef TEMPLIST_H_ #define TEMPLIST_H_
#include
using namespace std;
template class TemperatureList{ public: T* list; long size; long MAX_SIZE; TemperatureList(int n); void add_temperature(T temperature); bool full() const; long get_size() const; T get_temperature(long position) const; void output(ostream &outs) const; T get_last() const; void detele_last(); };
#endif
templist.cpp:
#include "templist.h"
template TemperatureList::TemperatureList(int n){ list = new T[n]; MAX_SIZE = n; size = 0; }
template void TemperatureList::add_temperature(T temperature){ if (full() == false){ list[size] = temperature; size += 1; } }
template bool TemperatureList::full() const{ if (size == MAX_SIZE) return true; return false; }
template long TemperatureList::get_size() const{ return size; }
template T TemperatureList::get_temperature(long position) const{ if (position >= size || position < 0) return 0.0; return list[position]; }
template void TemperatureList::output(ostream &outs) const{ for (long i = 0; i < size; i++) outs << list[i] << endl; }
template T TemperatureList::get_last() const{ if (size == 0) return 0.0; return list[size-1]; }
template void TemperatureList::detele_last(){ if (size > 0); size -= 1; }
main.cpp:
#include "templist.h"
int main(){ TemperatureList temp(50); temp.add_temperature(4.0); temp.add_temperature(7.0); temp.add_temperature(8.0); temp.add_temperature(9.6); cout << "Last element is : " << temp.get_last() << endl; return 0; }