Templates



 DEVELOP > c-Plus-Plus > Templates

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 30 Mar 2007 09:37:40 PM
Object: Templates
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?
.

User: "Alf P. Steinbach"

Title: Re: Templates 31 Mar 2007 02:45:25 AM
* zfareed@umd.umich.edu:


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

Post a complete small program that exhibits the problem.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.

User: "terminator"

Title: Re: Templates 31 Mar 2007 06:30:34 AM
On Mar 31, 5:37 am,
wrote:

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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER