5,013 views
1 1 vote
A function that  does the same operation on different data types is to be implemented using

a) macros   b) overloading  c) function templates  d) default arguments

1 Answer

3 3 votes
  • Function Template enables us to define a function that works for multiple data types.
template <typename T>
int compare(T a,T b) {
	if(a < b) return -1;
	else if(a > b) return 1;
	else return 0;
}

int main() {
	int x = 2;
	int y = 3;
	printf("%d\n",compare(x,y));

	double a = 2.3;
	double b = 1.3;
	printf("%d\n",compare(a,b));
}
Answer:
Position:
Show:

Related questions

4 4 votes
2 answers 2 answers
4.6k
4.6k views
Sanjay Sharma asked Dec 11, 2016
4,587 views
An electronic device used to connect different types of topologies having same protocol1)Repeater2)Router3)Bridge4)Switch
0 0 votes
1 answers 1 answer
1.1k
1.1k views