Advisory Board Interview Question: whats' the template in c++,ob... | Glassdoor

Interview Question

Software Engineer Interview Austin, TX

whats' the template in c++,object,class.


Interview Answer

1 Answer


Function templates are special functions that can operate with generic types. This allows us to create a function template whose functionality can be adapted to more than one type or class without repeating the entire code for each type.

// function template
using namespace std;

T GetMax (T a, T b) {
  T result;
  result = (a>b)? a : b;
  return (result);

int main () {
  int i=5, j=6, k;
  long l=10, m=5, n;
  cout << k << endl;
  cout << n << endl;
  return 0;

Ciberoid on Jul 24, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.