Invoke a template function?

Hello, I wrote out this coding to deal with template functions, but how would I invoke the function and to display the statements which im trying to invoke?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cstdlib>
#include <iostream>

using namespace std;
#include <string>

template <class Anytype>
bool search(Anytype ary[], Anytype key, int size)
{
     int j; bool notFound = false;
     j=0;
     while(j<=size&&notFound==false)
     {
                      if(key==ary[j])
                      notFound = true;
                      else
                      ++j;
                      }
                      return notFound;
     }
int main()
{
    float a[]={3.2,4.8,9.1,15.99}, float_key;
    int b[] = {12,1,8}, int_key;
    cout<<"Enter float key: "<<endl;
    cin>>float_key;
    cout<<"Enter int key: "<<endl;
    cin>>int_key;
    search(a,float_key,4);
    search(b,int_key,3);
    system("PAUSE");
}
how would I invoke the function and to display the statements which im trying to invoke?


I'm not sure what you mean by this, could you rephrase?
I'm sorry for not being clear haha but I was also being stupid ive managed to fix my problem, I am trying to verify the program is working such as in int main, search(a,float_key,4), when float_key is entered by the user, it would search through float a[]=(3.2, 4.8, 9.1, 15.99) and would see if the number entered was in the array. Ive edited my coding so that now it displays 1 or 0, 1 for being in the array and 0 for it not being in the array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <cstdlib>
#include <iostream>

using namespace std;
#include <string>

template <class Anytype>
bool search(Anytype ary[], Anytype key, int size)
{
     int j; bool notFound = false;
     j=0;
     while(j<=size&&notFound==false)
     {
                      if(key==ary[j])
                      notFound = true;
                      else
                      ++j;
                      }
                      return notFound;
     }
int main()
{
    float a[]={3.2,4.8,9.1,15.99}, float_key;
    int b[] = {12,1,8}, int_key;
    cout<<"Enter float key: "<<endl;
    cin>>float_key;
    cout<<"Enter int key: "<<endl;
    cin>>int_key;
    float z;
    z = search(a,float_key,4);
    cout<<"If 1, float value entered was in array, if 0, float value was not in array :"<<z<<endl;
    int t;
    t = search(b,int_key,3);
    cout<<"If 1, int value entered was in array, if 0, int value was not in array :"<<t<<endl;
    system("PAUSE");
}
Topic archived. No new replies allowed.