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();
}

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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.