[ create a new paste ] login | about

Link: http://codepad.org/6RVU81nM    [ raw code | output | fork ]

C++, pasted on Jul 29:
#include <iostream>
#include <string>

template <typename R>
R f(int a, int b);

template <>
int f<int>(int a, int b)
{
  return a + b;
}

template <>
std::string f<std::string>(int, int)
{
  return "surprise";
}

template <typename T>
void g(int a, int b, T& res)
{
  res = f<T>(a, b);
}

int main()
{
  int x;
  std::string y;

  g(1, 2, x);
  g(1, 2, y);

  std::cout << "x = " << x << ", y = " << y << std::endl;
}


Output:
1
x = 3, y = surprise


Create a new paste based on this one


Comments: