Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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):

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; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

Students also viewed these Databases questions

Question

Create a corporate story for a company with which you are familiar.

Answered: 1 week ago