0

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

Edited by Obsidian_496: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by macobex
0

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

0

PHP equivalent function of your code posted above.

function GetMax($a, $b){
   $result = ( $a > $b ) ? $a : $b;
   return $result;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.