Boost logo

Boost Users :

From: Jeff Garland (jeff_at_[hidden])
Date: 2005-04-24 14:14:09


On Sun, 24 Apr 2005 14:46:22 -0400, Stephen Torri wrote
>...snip...
>
> Each item expect a distinctive input type. If it receives something that
> it does not know how to handle or need I want to throw an error.
>
> In order to do this I would like to do something like:
>
> void process (Base* sobj)
> {
> if (! (isExpectedType(sobj))
> {
> throw NotForMeException ();
> }
>
> Brake_Pedal* bp = dynamic_cast<Brake_Pedal>(sobj);
> bp.set_pressure (50);
> }
>
> So perhaps my design is flawed that I am running into this
> situation.

I'd say so. You might want to read about the Liskov Substitution Principle:
http://www.objectmentor.com/resources/articles/lsp.pdf

Jeff


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net