There are function and class templates in C++. They can operate with generic data types.
There's some ifnormation on it.
http://www.cplusplus.com/doc/tutori
al/templates/

This is a compile-able example from the site linked above:

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

template <class T>
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;
  k=GetMax<int>(i,j);
  n=GetMax<long>(l,m);
  cout << k << endl;
  cout << n << endl;
  getch();
  return 0;
}

I wonder, could I do the same in php? From what I've found so far, I can't. Templates in C++ and PHP seem like completely different things, at least now. I hope you understand the question.

Was not sure where to post this either, in php or c+ section.

I hope that someone with knowledge in both PHP and C++ will help. Thanks :)

I don't think PHP supports templates, considering the fact that it is a dynamic language.

PHP equivalent function of your code posted above.

function GetMax($a, $b){
   $result = ( $a > $b ) ? $a : $b;
   return $result;
}
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.