This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: upcast-downcast
- From: Martin Brain <mjb at cs dot bath dot ac dot uk>
- To: gcc at gcc dot gnu dot org
- Cc: Fabio Salvucci <dsmoker at libero dot it>
- Date: 30 Jul 2003 20:08:12 +0100
- Subject: Re: upcast-downcast
- References: <20030730175054.A193@libero.it>
<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