Variable test

Hi, I need make one function with different returns. Can you help me? .. Best for win32. I tried the search on google but I didn't find.

It should work on the principle of handover of some variable in the function, which evaluates it and sends back the exact type.

It should look like this somehow:
1
2
3
4
5
6
7
8
9
<variable> Test(<variable> x) {
...
if(x .?.)
return x; //as int
if(x .?.)
return x; //as char

and next
}


.. Google english ..
Just curious, why do you think you need this? What are you doing that requires this? There may be a better solution altogether.
Last edited on
1
2
3
4
5
template <typename T>
T Test(T x) { 
  // manipulate x generically
  // return x 
} 


See the tutorial on templates at this site:
http://www.cplusplus.com/doc/oldtutorial/templates/
I also think you should read those tutorials as they can help you a lot. Miss understanding can cause errors which you really don't want. Those errors must be detected quickly. If you find it troubling you can always try using a software to help you do that. I tend to use checkmarx which works fine.
Good luck.
Ben.
Topic archived. No new replies allowed.