From: "Paul Ranson"
This is a multi-part message in MIME format.
------=_NextPart_000_0025_01C4C646.E324B2E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
"Geo" wrote in message
news:419003c2$1{at}w3.nls.net...
> Ok but that doesn't explain what the difference between a data type =
like
> "int" and a class like "Date" is.
The intention is that there is no difference, but it's not quite that =
simple. In order to retain efficiency and C compatibility an 'int' is an =
intrinsic type directly understood (in general) by the CPU. This is why =
its size is not fixed by the language, different CPUs have different = word
lengths and an 'int' or 'unsigned' is intended to be the natural = fit to
that.
In C++ it's possible to implement the operators ('+', '-', etc) so you =
could create a 'class Int' that looked and felt much like the built in =
'int'. For an example of this consider the library supplied class =
'complex' which implements complex numbers (it's actually a template so =
you can use ints, doubles, or whatever else exists on your machine, as =
the real and imaginary parts).
In the timing stuff somewhere up thread I wrote something like,
double Evaluate ( complex c ) {
for ( unsigned u =3D 0; u < 10000; ++u )
c =3D c * c + c ;
return abs ( c ) ;
}
Which makes 'complex' look a lot like any built in numeric type, if we =
rewrote it as a template,
template T Evaluate ( T t ) {
for ( unsigned u =3D 0; u < 10000; ++u )
t =3D t * t + t ;
return abs ( t ) ;
}
Then we could call it with any type of our choosing that supported '*', =
'+' and 'abs'.
int n =3D Evaluate ( 100 ) ;
complex c =3D Evaluate ( complex ( 0.1, -0.2 ) ;
The only difference between an 'int' and a putative 'class Int' that I =
can immediately think of is that you cannot inherit from an 'int'. There =
are probably others but we're getting deep into language lawyerdom...
Paul
------=_NextPart_000_0025_01C4C646.E324B2E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
"Geo" <mailto:georger{at}nls.net">
size=3D2>georger{at}nls.net> wrote in message =
news:419003c2$1{at}w3.nls.net...
> Ok but that doesn't explain what
the difference =
between a=20
data type like> "int" and a class like
"Date" = is.
The intention is that there is no difference, but =
it's not=20
quite that simple. In order to retain efficiency and C compatibility an =
'int' is=20
an intrinsic type directly understood (in general) by the CPU. This is = why its=20
size is not fixed by the language, different CPUs have different word = lengths=20
and an 'int' or 'unsigned' is intended to be the natural fit to=20
that.
In C++ it's possible to implement the operators =
('+', '-',=20
etc) so you could create a 'class Int' that looked and felt much like = the built=20
in 'int'. For an example of this consider the library supplied class =
'complex'=20
which implements complex numbers (it's actually a template so you can = use ints,=20
doubles, or whatever else exists on your machine, as the real and = imaginary=20
parts).
In the timing stuff somewhere up thread I wrote =
something=20
like,
double Evaluate =
(=20
complex<double> c )
{
=
for ( unsigned u=20
=3D 0; u < 10000; ++u )
c =3D c * c
+ c ;
=
return abs ( c )=20
;
}
Which makes 'complex' look a lot like any built in =
numeric=20
type, if we rewrote it as a template,
template<typename T> T=20 Evaluate
( T t )
{
=
for ( unsigned u=20
=3D 0; u < 10000; ++u )
t
=3D t * t =
+ t=20
;
=
return abs=20
( t ) ;
}
Then we could call it with any type of our choosing =
that=20
supported '*', '+' and 'abs'.
int n =3D =
Evaluate ( 100 )=20
;
complex<double> c =3D=20 Evaluate (
complex<double> ( 0.1, -0.2 ) ;
The only difference between an 'int' and a putative =
'class=20
Int' that I can immediately think of is that you cannot inherit from an =
'int'.=20
There are probably others but we're getting deep into language=20
lawyerdom...
Paul
------=_NextPart_000_0025_01C4C646.E324B2E0--
--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)
SEEN-BY: 633/267 270 5030/786
@PATH: 379/45 1 396/45 106/2000 633/267
|