Templates

Z

zfareed

int main()
{
ifstream inFile;
ifstream inFile2;

int x,y=0;
float z;
int number;
bool found;

SortedList<int> Aint;
SortedList<float> Bfloat;
SortedList<ItemType> C;

/* Read in data from two data files
one is a list of integers to be inserted into int SortedList
and the other a list of float to be inserted into float SortedList
*/
inFile.open("int.dat");
cout << "The number of elements in the first file: ";
cout << numIntElement(inFile,j)<< endl;
cout << endl;
inFile.close();
inFile.open("int.dat");

inFile2.open("float.dat");
cout << "The number of elements in the second file: ";
cout << numFloatElement(inFile2,y)<< endl;
cout << endl;
inFile2.close();
inFile2.open("int.dat");
for(int t=0;t<y;t++)
{
inFile2 >> z;
Bfloat.InsertItem(z);
}
Bfloat.ResetList();
for(int s=0;s<y;s++)
{

Bfloat.RetrieveItem(a,found); // the errors are here

/*Bfloat.GetNextItem();*/ //

}

I am tryimg to call a function of a class template in the main
program. the instance Bfloat is calling the RetrieveItem method to
find a value in a float list.
ERROR:
templatedriver.cpp no matching function for call to
`SortedList<float>::RetrieveItem(ItemType&, bool&)'
candidates are: void SortedList<ItemType>::RetrieveItem(ItemType&,
bool&) const [with ItemType = float]

The function name is below.

template<class ItemType>
void SortedList<ItemType>::RetrieveItem(ItemType &a,bool &found) const
{


I had no errors with the InsertItem function. Can anyone help please?
 
A

Alf P. Steinbach

* (e-mail address removed):
I had no errors with the InsertItem function. Can anyone help please?

Post a complete small program that exhibits the problem.
 
T

terminator

int main()
{
ifstream inFile;
ifstream inFile2;

int x,y=0;
float z;
int number;
bool found;

SortedList<int> Aint;
SortedList<float> Bfloat;
SortedList<ItemType> C;

/* Read in data from two data files
one is a list of integers to be inserted into int SortedList
and the other a list of float to be inserted into float SortedList
*/
inFile.open("int.dat");
cout << "The number of elements in the first file: ";
cout << numIntElement(inFile,j)<< endl;
cout << endl;
inFile.close();
inFile.open("int.dat");

inFile2.open("float.dat");
cout << "The number of elements in the second file: ";
cout << numFloatElement(inFile2,y)<< endl;
cout << endl;
inFile2.close();
inFile2.open("int.dat");
for(int t=0;t<y;t++)
{
inFile2 >> z;
Bfloat.InsertItem(z);
}
Bfloat.ResetList();
for(int s=0;s<y;s++)
{

Bfloat.RetrieveItem(a,found); // the errors are here

/*Bfloat.GetNextItem();*/ //

}

I am tryimg to call a function of a class template in the main
program. the instance Bfloat is calling the RetrieveItem method to
find a value in a float list.
ERROR:
templatedriver.cpp no matching function for call to
`SortedList<float>::RetrieveItem(ItemType&, bool&)'
candidates are: void SortedList<ItemType>::RetrieveItem(ItemType&,
bool&) const [with ItemType = float]

The function name is below.

template<class ItemType>
void SortedList<ItemType>::RetrieveItem(ItemType &a,bool &found) const
{

I had no errors with the InsertItem function. Can anyone help please?

I did not find the declarartion of 'a' any where inside the code .I
guess the compiler did not either.Hence it has the right to complain.

cheers,
FM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

class templates 4
class templates 0
Class templates 1
Classes,lists 4
Lexical Analysis on C++ 1
mainMenu keeps on appearing at the end of every option 3
I need help 1
Urgent help: print elements in queue 4

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top