|
Boost : |
From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-03-24 11:17:35
On Mon, 24 Mar 2003 07:24:38 -0500, David Abrahams
<dave_at_[hidden]> wrote:
>I don't think I've ever read a
>description of LSP which doesn't leave that question completely
>unaddressed.
I've never seen a formulation of LSP which was appliable to C++.
"If for each object o1 of type S there is an object o2 of
type T such that for all programs P defined in terms of T,
the behavior of P is unchanged when o1 is substituted for
o2 then S is a subtype of T."
Even a simple overloading of two functions (if we don't want to
disturb reference binding) seems to put it in serious trouble:
void f(int) { something... }
void f(short) { something else... }
int main() {
int i = 0;
f(i);
}
This is a program defined "in terms of int". Can you substitute a
short 0 (zero) to i? Also, I've never understood how one can generally
("all programs") substitute an object (rather than a type) in a
program without modifying the program itself. Maybe that's just my
ignorance. And even modifying the program, what is the supposed
substitution LSP refers to in the above case?
a) int i = (short)0;
f(i);
b) short i = 0;
f(i)
When "o1 is substituted for o2"? Where? How?
Genny.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk