Article View: alt.comp.lang.learn.c-c++
Article #381Re: Function Templates
From: Brent Worden
Date: Sun, 07 Mar 1999 00:00
Date: Sun, 07 Mar 1999 00:00
28 lines
1773 bytes
1773 bytes
In article <01be6806$77c8e6a0$LocalHost@mckinniss>,
"Eric & Tammy" <ericandtammy@unforgettable.com> wrote:
> I need to write a "template function" (i.e., template <class highest>)that
> returns the largest of three numbers of the same type passed to it as
> arguments. Any help, suggestions, or ideas would be appreciated.
>
>
Compare the first two values, taking the largest of the two.
Compare this item with the remaining value, return the largest.
This is quite elegant using max from the stl.
#include <algorithm>
template<class Type>
Type FindLargest(Type a, Type b, Type c)
{
return std::max( std::max(a, b), c);
};
|==============================|
| Brent Worden |
| http://www.Brent.Worden.org/ |
|==============================|
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Technical Details
Message-ID:
<7bskot$scm$1@nnrp1.dejanews.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<01be6806$77c8e6a0$LocalHost@mckinniss>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,a166b609beeb1a7f X-Google-Attributes: gidf8d38,public X-Google-Thread: 114592,a166b609beeb1a7f X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,a166b609beeb1a7f X-Google-Attributes: gid109fba,public From: Brent Worden <brent.worden@poboxes.com> Subject: Re: Function Templates Date: 1999/03/07 Message-ID: <7bskot$scm$1@nnrp1.dejanews.com> X-Deja-AN: 452057348 References: <01be6806$77c8e6a0$LocalHost@mckinniss> X-Http-Proxy: 1.0 x11.dejanews.com:80 (Squid/1.1.22) for client 132.174.38.110 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Sun Mar 07 01:29:07 1999 GMT Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.lang.c++ X-Http-User-Agent: Mozilla/4.07 [en] (WinNT; U)