Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another template question

Status
Not open for further replies.

grscot

Programmer
Apr 25, 2003
16
GR
Dear all,

I 've understood that the template function for the two functions :
int AddNumbers(int a, int b);
float AddFloats(float a, float b);

is: template<class T>
T Add(const T &a, const T&b)
{
return a+b;
}
because the arguments' return type is the same as the functions' return type.

But what is the template function when the return type of the arguments is different from the return type of the function?
For example:
Member* get_member(Book* book);
Book* get_book(Member* member);

What is now the template function of the two above functions?

Regards,
grscot
 
Huh?

The question doesn't make sense.

And arguments don't have return types.


Are you asking what function template could be used to instantiate those two functions? If so, the answer is &quot;none.&quot; The two functions have different names.

If they had the same name, theoretically, you could have a function template as follows:

Code:
  template< class Ret, class Arg >
Ret* get( Arg* );
That could be used to instantiate the two functions, but only if their implementation was exactly identical, which is doubtful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top