So I'm trying to write a program that is due tomorrow. I am trying to overload operators and dealing with template classes. I have everything written already but keep getting this error whenever i try to compile the driver file:
NOTE: proj4.cpp has #include "box.h" and box.h compiles fine, but it says box.h has errors whenever i try to compile proj4.cpp
student@student-desktop:~$ g++ -c proj4.cpp
box.h: In member function ‘void listT<elemType>::insert(elemType) [with elemType = Box]’:
proj4.cpp:51: instantiated from here
box.h:18: error: ‘bool Box::operator<(Box&)’ is private
listT.cpp:63: error: within this context
Here is some of the code that I think is part of the problem:
box.h:
#ifndef _Box_H
#define _Box_H
#include <iostream>
#include <string>
using namespace std;
class Box
{
//Insertion(<<) operator definition
friend ostream& operator<< (ostream&, const Box&);
//Extraction(>>) operator definition
friend istream& operator>> (istream&, Box&);
//Equality(==) operator definition
bool operator== (Box&);
//Greater than(>) operator definition
bool operator> (Box&);
//Less than(<) operator definition
bool operator< (Box&); *********************************************LINE18 ERROR
box.cpp:
//Overloading equality(==) operator
bool Box::operator== (Box& box)
{
return (getSurfaceArea() == box.getSurfaceArea());
}
//Overloading greater than(>) operator
bool Box::operator> (Box& box)
{
return (getSurfaceArea() > box.getSurfaceArea());
}
//Overloading less than(<) operator
bool Box::operator< (Box& box)
{
return (getSurfaceArea() < box.getSurfaceArea());
}
listT.cpp:
template<class elemType>
void listT<elemType>::insert(elemType insertItem)
{
elemType temp;
list[length++] = insertItem;
for(int i = length - 1; i >= 0; i--)
{
if(list[i] < list[i-1])*********************************LINE63 ERROR
{
temp = list[i];
list[i] = list[i-1];
list[i-1] = temp;
}
}
} // end insert
proj4.cpp:
//Load data into array
inFile >> boxTemp;
bList.insert(boxTemp);**********************************************LINE 51 ERROR
while(inFile)
{
inFile >> boxTemp;
bList.insert(boxTemp);
}
Can anyone help me? thanks again.