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 :)