home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Type System
- Message-ID: <1993Jan1.172044.9659@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- Date: Fri, 1 Jan 1993 17:20:44 GMT
- Lines: 62
-
- Further to a previous post describing modifications to the type
- system, I want to try to explain the underlying concept with some
- further examples.
-
- The basic idea is that 'int' and 'T' are object types,
- whereas 'int&' or 'const int&' are not object types.
- I would say they are 'accessors' to an object of type 'int'.
-
- All identifiers (and expressions) are accessors.
- Consider:
-
- int x;
- int& y=x;
- const int& z=x;
-
- In use, one cannot distinguish 'x' and 'y'. It is absurd IMHO
- to pretend that 'x' is of type 'int' whereas 'y' is of type 'int&'.
- Instead, one says that 'x' and 'y' and indeed 'z' refer to,
- or access, an object of type int.
-
- The 'access' method of both 'x' and 'y' is reference to int,
- i.e. they are both 'int&'. 'z' is also a reference to an
- int, but it has a restriction imposed preventing the call
- of non-const functions.
-
- Consequences: of this and the previous post:
-
- consider a template function:
-
- template<class T> f(T){ ... }
-
- what function is generated by the calls
-
- f(3);
- f(x);
- f(y);
- f(z);
- ??
-
- My system is simple: in all cases
-
- f(int);
-
- is used. If you wanted to create
-
- f(int&);
-
- you should have defined
-
- template<class T> f(T&) { ...}
-
- (in which case the calls f(3), f(z) are illegal)
-
- The reason is trivial: <class T> stands for a class (or pointer)
- type, ie an object type, and int& is not a type, but a reference
- to an object of the type int.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-