I have the following driver for my template class the parameter being passed to the template is another class, the error I get is


Error line 28 : templateclass.h std::ostream<<ballteam is illegal
driver.cpp line 30 Where instationating templateclass<ballTeam>::print const ()

driver

#include <iostream>
#include <fstream>
#include "arrayListTypeT.h"
#include "ballTeam.h"
using namespace std;


int main()
{
  arrayListTypeT<ballTeam> teamList(10);
  ballTeam team;
  fstream fin;
  
  fin.open("teamStats.data");
  
  if(!fin.is_open())
    cout<<"Error: File does not exist or error opening file\n"<<endl;
  
  while(!fin.eof())
  {
    fin>>team;
    teamList.insert(team);
    
    
  }
   
  
  fin.close();

 teamList.print();
  
  return 0;
}

Class I am passing to template as parameter

#include <iostream>
#include "ballTeam.h"
using namespace std;

ballTeam::ballTeam()
{
  name = "";
  wins = 0;
  losses = 0;
  totalPoints = 0;
}

ballTeam::ballTeam(string tName, int tWins, int tLosses, int tTotal)
{
  name = tName;
  wins = tWins;
  losses = tLosses;
  totalPoints = tTotal;
}

void ballTeam::set(string tName, int tWins, int tLosses, int tTotal)
{
  name = tName;
  wins = tWins;
  losses = tLosses;
  totalPoints = tTotal;
}

string ballTeam::getName() const
{
  return name;
}

int ballTeam::getWins() const
{
  return wins;
}

int ballTeam::getLosses() const
{
  return losses;
}

int ballTeam::getTotal() const
{
 return totalPoints;
}

bool ballTeam::operator==(const ballTeam &team)
{
  float ratio;
  float teamRatio;
  ratio = (wins/ (float)(wins + losses));
  teamRatio = (team.wins/ (float)(team.wins + team.losses));
  
  return (ratio == teamRatio);
}

bool ballTeam::operator>(const ballTeam &team)
{
  float ratio;
  float teamRatio;
  ratio = (wins/ (float)(wins + losses));
  teamRatio = (team.wins/ (float)(team.wins + team.losses));
  
  return(ratio > teamRatio);
}

bool ballTeam::operator<(const ballTeam &team)
{
  float ratio;
  float teamRatio;
  ratio = (wins/ (float)(wins + losses));
  teamRatio = (team.wins/ (float)(team.wins + team.losses));
  
  return (ratio < teamRatio);
}

istream & operator>>(istream & in, ballTeam &team)
{
  in>>team.name>>team.wins>>team.losses>>team.totalPoints;
  
  return in;
}

Template class code

// Implementation of the templated version of arrayListType
#include <iostream>
#include <cassert>
#include "arrayListTypeT.h"

using namespace std;

template<class elemType>
bool arrayListTypeT<elemType>::isEmpty() const
{ return (length == 0); }

template<class elemType>
bool arrayListTypeT<elemType>::isFull() const
{ return (length == maxSize); }

template<class elemType>
int arrayListTypeT<elemType>::listSize() const
{ return length; }

template<class elemType>
int arrayListTypeT<elemType>::maxListSize() const
{ return maxSize; }

template<class elemType>
void arrayListTypeT<elemType>::print() const
{
	for (int i = 0; i < length; i++)
		cout << list[i] << " ";
	cout << endl;
}

template<class elemType>
bool arrayListTypeT<elemType>::isItemAtEqual(int location, elemType item) const
{ return(list[location] == item); }

template<class elemType>
void arrayListTypeT<elemType>::removeAt(int location)
{
	if (location < 0 || location >= length)
    	cout << "The location of the item to be removed "
			 << "is out of range." << endl;
	else
	{
   		for (int i = location; i < length - 1; i++)
	 		list[i] = list[i+1];
		length--;
	}
} //end removeAt

template<class elemType>
void arrayListTypeT<elemType>::retrieveAt(int location, elemType& retItem)
{
	if (location < 0 || location >= length)
    	cout << "The location of the item to be retrieved is "
			 << "out of range." << endl;
	else
		retItem = list[location];
} // retrieveAt

template<class elemType>
void arrayListTypeT<elemType>::replaceAt(int location, elemType repItem)
{
	if (location < 0 || location >= length)
    	cout << "The location of the item to be replaced is "
			 << "out of range." << endl;
	else
		list[location] = repItem;

} //end replaceAt

template<class elemType>
void arrayListTypeT<elemType>::clearList()
{
	length = 0;
} // end clearList

template<class elemType>
arrayListTypeT<elemType>::arrayListTypeT(int size)
{
    if (size <= 0)
    {
        cout << "The array size must be positive. Creating "
             << "an array of size 100. " << endl;
        maxSize = 100;
    }
    else
        maxSize = size;
    length = 0;
    list = new elemType[maxSize];
    assert(list != NULL);
}

template<class elemType>
arrayListTypeT<elemType>::~arrayListTypeT()
{ delete [] list; }

template<class elemType>
arrayListTypeT<elemType>::arrayListTypeT(const arrayListTypeT<elemType>& otherList)
{
    maxSize = otherList.maxSize;
    length = otherList.length;
    list = new elemType[maxSize];  //create the array
    assert(list != NULL);          //terminate if unable to allocate

    for (int j = 0; j < length; j++)  //copy otherList
        list [j] = otherList.list[j];
}//end copy constructor

template<class elemType>
int arrayListTypeT<elemType>::seqSearch(elemType item)  const
{
	int i;
	for (i = length - 1; i >= 0; i--)
	   if (list[i] == item)
	   { break; }
	return i;
} //end seqSearch

template<class elemType>
void arrayListTypeT<elemType>::insert(elemType insertItem)
{
  // Your code to insert a new item into the list goes here.
  // You are required to check for the following errors:
  // Duplicate insertion.
  // Full list.
  // If either error occurs, display an appropriate message leave the 
  // list unchanged.
  
  
  if(isFull())
     cout<<"Cannot insert item, list is full.\n"<<endl;
   
   for(int i = 0; i < length; i++)
   {
     if(list[i] = insertItem)
     {
       cout<<"Duplicate Item in list\n"<<endl;
       break;
     }
     else
     {
        list[length] = insertItem;
        length++;
     }
   }
} //end insert

template<class elemType>
void arrayListTypeT<elemType>::remove(elemType removeItem)
{
	int loc;
	if (length == 0)
		cout << "Cannot delete from an empty list." << endl;
	else
	{
		loc = seqSearch(removeItem);

		if (loc != -1)
			removeAt(loc);
		else
			cout << "The team to be deleted is not in the list."
				 << endl;
	}
} //end remove

Recommended Answers

All 4 Replies

Well you don't seem to have written a operator>> for class ballTeam. I could be wrong since you didn't include the definition files (.h files).

I

No I have written a >> operator overload, it is in the second code block at the bottom

Bump...Veron where are you!?! lol XD

Sorry for the bump, after some decent concetration I needed to overload the ostream operator the poster who replied must have had a typo, thanks anyway solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.