0

i used template funtion but its not working...
it shows error like.......
could not find match for func(char *,int)....
in this program i m tring to find a charcter's location from user provided 5 characters.
for this used template function...

#include<iostream.h>
#include<conio.h>
template<class temp>
int func(temp *array[],temp loc)
{
		char ch;
		cout<<"\n which alphabet u want to find: ";
		cin>>ch;

		for(int j=0;j<loc;j++)
		{
			if(array[j]==ch)
		}
			return j;
}


void main()
{
	const int max=10;
	char arr[max];
	int num,i;
	clrscr();

	cout<<"\n enter a number for how many times u want to type alphabet: ";
	cin>>num;

	for(i=0;i<num;i++)
	{
		cin>>arr[i];
	}


  cout<<func(arr,num);


getch();
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by programmersbook
0

here you go:

#include <iostream>
//#include <conio.h>

using namespace std;

template<typename T, typename C>
T func(T *array,C loc)
{ 
		T ch;
		cout<<"\n which alphabet u want to find: ";
		cin>>ch;

		for(C j=0;j<loc;j++)
		{
			if(array[j]==ch){
			   return j;
			}
		}
	
	return 0;
}


int main()
{
	const int max=10;
	char arr[max];
	int num,i;
	clrscr();

	cout<<"\n enter a number for how many times u want to type alphabet: ";
	cin>>num;

	for(i=0;i<num;i++)
	{
		cin>>arr[i];
	}

  cout << func<char, int>(arr, num) << endl;

   getch();
  
  return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.