Thread View: comp.std.c++
2 messages
2 total messages
Started by Xristos Kilitzirakis
Thu, 12 Nov 1992 07:34
c++ implementation (hard)
Author: Xristos Kilitzirakis
Date: Thu, 12 Nov 1992 07:34
Date: Thu, 12 Nov 1992 07:34
32 lines
1298 bytes
1298 bytes
Welcome to the hardline accoarding to XXXristos. here's the problem: suppose class a is a base class and b,c are derived,that is: a--->b | ---->c 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) It may look easy to you,but for me is ... 'the answer is always easy , when you know it' XXXXristos e-mail yr answers in kilitzir@csd.uch.gr kilitzir@csi.forth.gr
Re: c++ implementation (hard)
Author: Markku Sakkinen
Date: Thu, 12 Nov 1992 14:54
Date: Thu, 12 Nov 1992 14:54
45 lines
2547 bytes
2547 bytes
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
----------------------------------------------------------------------
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads