|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> And it's not like C++ supports precompiled templates, either. :-)
Not to create new code (obviously), but you can precompile explicit
instantiations of template code into a library. If the user is expected
to use only those specific types with the library, then you don't actually
have to provide any code. (You lose the flexibility of templates from the
user's point of view, but you still have the flexiblity from the point of
view of the library developer.)
> >
> >>> I wonder if Eiffel supports this as well.
> >
> >> Eiffel lets you cast up and down the heirarchy. All methods are semantically
> >> virtual (even if the compiler optimizes them to direct jumps), so the fact
> >> that you're casting up and down doesn't make it "invalid". You can't cast a
> >> reference to an object to a type that isn't in that object's parent class
> >> heirarchy.
> >
> > Does that mean "no"?
> I wasn't 100% sure what the "this" was.
You have two completely unrelated classes A and B (ie. they don't inherit
from each other in any way, or have anything in common), and you can do this:
void foo(A* aPtr)
{
B* bPtr = dynamic_cast<B*>(aPtr);
if(bPtr)
...
}
The dynamic_cast will succeed if the object pointed by aPtr is in actuality
of a type which has been multiple-inherited from A and B (even if by a very
long inheritance chain). The foo() function doesn't need to know anything
about that class in question, and can eg. be precompiled into a library.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |