How to template determine return type and passing type? (modifier)

I want to have two overloads of a function one that returns int and another long long int based upon the value that is being returned. Can template do this?

What about passing parameters? Are modifiers considered for templates in that situation?

Does template make short int or int if I pass in say, for example, 5. What if I want short int to be considered (when appropriate of course).

Last edited on
C++ overload resolution is done based on the arguments, but not the return value. So you can't have two functions that differ only in the return type.
Does template make short int or int if I pass in say, for example, 5

Read this: http://www.cplusplus.com/doc/tutorial/typecasting/
Can template do this?
Yes:
1
2
3
4
5
6
7
8
9
10
11
12
template<typename result_type>
result_type foo(...)
{
  result_type res;
...
  return res;
}

...

int x = foo<int>(...);
long long int y = foo<long long int>(...);
Topic archived. No new replies allowed.