You are just missing a couple of things to get the code compiling (resolving the error you saw).
Basically, in int main()
, you need to specify the type when instantiating the template, as in:
Read_Data <int> (key, value);
so that the compiler knows what type you really want to instantiate it with.
Also note that the array should be of type int *
. So in the templated function the signature has to change to:
template<class type> Read_Data( type &key , type* &arr)
This is the corrected code which won't show the error you were previously seeing:
#include<iostream>
using namespace std;
int size , found = -1 ;
template<class type> void Read_Data( type &key , type* &arr)
{
cout << " please enter the size of your set \n " ;
cin >> size ;
arr = new type[size];
cout << " please enter the elements of your set : \n " ;
for (int i = 0 ; i <size ; i ++ )
{
cout << " enter element number " << i << ": " ;
cin >> arr[i] ;
}
cout << " please enter the key elemente you want to search for : \n " ;
cin >> key;
}
int main()
{
int key;
int * arr;
Read_Data<int> (key, arr);
/* after these function there is two other functions one to search for key
* in array "arr" and other to print the key on the screen
*/
}