How to pass 'numbers' (int, float...) to a single variable into a function ?

I know overload methods but.... Is there some type to receive numbers and later know the real type ?
In the old VB it was the 'variant' type.


I'd want to have :

void myfunction( anytype calue){
if anytype is float .....
if anytype is double .....


Thanks.
http://www.cplusplus.com/doc/tutorial/templates/ (scroll down to template specialization)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
template <class T>
void myfunction(T value)
{
   cout <<"Generic template"<<endl;
}

template <> void myfunction(float value)
{
   cout <<"Template spacialization  for float"<<endl;
}

template <> void myfunction(int value)
{
   cout <<"Template specialization for int"<<endl;
}


int main ()
{
myfunction(3.14f);
myfunction(3);

myfunction("str");

  return 0;
}
At that point you don't even need templates. Just make non-templated overloads.

But I'm not sure that's what is being asked for. OP needs to clarify.
Topic archived. No new replies allowed.