upcast-downcast
Martin Brain
mjb@cs.bath.ac.uk
Wed Jul 30 19:57:00 GMT 2003
<snip>
> #######################################
>
> I would like write code like this :
>
> write ( data_stored_in_Data_vect[1] ,data_stored_in_Data_vect[2] ) ;
>
> #######################################
<snip>
> The compiler at runtime check that exist a function after (DOWNCAST)
> "write(class* ,char* )" and then call it.
>
> write This C++ code will be possible in the future??
>From my understanding of what you're asking - your problem essentially
requires dynamic (run time) function dispatch based on the type of two
objects.
Run time function dispatch does exist - it's how virtual functions work
but at the moment (at the compiler level) this is supported for one type
only.
The bad news is - I highly doubt this will be supported any time soon as
it is a major change to how the language works. You would be best off
asking on the forums for the development of the C++ language. I highly
doubt it is beyond the skill of the g++ team but it is a major change in
how the language should work so I'd wait until it turns up in the
standard.
The good news - IIRC there is a way of doing this leveraging existing
C++ idioms. Multimethods - Chapter 11 of "Modern C++ Design" by Andrei
Alexandrescu (ISBN 0-201-70431-5) contains an elegant implementation of
this sort of system and I would advise you get yourself a copy if you
want to build systems based on these ideas.
Cheers,
- Martin
More information about the Gcc
mailing list