home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!mcsun!news.funet.fi!network.jyu.fi!sakkinen
- From: sakkinen@jyu.fi (Markku Sakkinen)
- Subject: Re: c++ implementation (hard)
- Message-ID: <1992Nov12.145426.18594@jyu.fi>
- Keywords: c++
- Organization: University of Jyvaskyla, Finland
- References: <kilitzir.721552974@news.forth.gr>
- Date: Thu, 12 Nov 1992 14:54:26 GMT
- Lines: 45
-
- In article <kilitzir.721552974@news.forth.gr> kilitzir@antigone.csi.forth.gr (Xristos Kilitzirakis) writes:
- > ...
- >all right by then.The problem is,that any operator between these
- >2 classes , can give any of the 4 classes,depending on many
- >things , not only the type of operands.for ex.
- >a+b --->c|d|a,
- >so I cannot define the return type ,before inspecting the operands.
- >
- >Any suggestions of implementing (reordering,add a new class,
- > forgetting the hole thing, etc). ^^^^^^^^^^^^^^^
- >
- >Well , the implementation is
- >a -> m_n matrix
- >b-> n-n topelitz matrix (needs only 2*n-1 elems)
- >c-> n_n circulant matrix(needs only n elems)
- > ...
-
- No wonder that this looked like a potential "standards" problem to you.
- However, there is a conventional technique to do this kind of thing;
- it is applicable to other statically-typed OOPLs as well.
- It's described in Stroustrup's second edition: "13.9 Handle Classes".
- Essentially, you define a Matrix class with the correct interface
- (this is the handle class), and then any number of classes that
- implement the different representations, and whose instances
- the Matrix objects create and handle "behind the scenes".
- They would probably not be actually derived from Matrix.
-
- The inconvenient thing here is that you must write all member functions
- both in the representation classes and in the handle class (which just
- passes most calls to the representation object). Indeed, a delegation
- facility was added to an experimental version of C++ together with
- the first implementation of multiple inheritance (described in
- Stroustrup's paper in the EUUG Spring Conference proceedings, 1987)
- to avoid such chores. However, it was abandoned because it appeared
- to be error-prone in use.
-
- ----------------------------------------------------------------------
- Markku Sakkinen (sakkinen@jytko.jyu.fi)
- SAKKINEN@FINJYU.bitnet (alternative network address)
- Department of Computer Science and Information Systems
- University of Jyvaskyla (a's with umlauts)
- PL 35
- SF-40351 Jyvaskyla (umlauts again)
- Finland
- ----------------------------------------------------------------------
-