On 29 avr, 00:00, "Hak...@[EMAIL PROTECTED]
" <Hak...@[EMAIL PROTECTED]
> wrote:
> I have two issues.
>
> 1) Given the objects item1 and item2, derived from type T, I need to
> find out if item2 is derived from item1.
You could use the visitor pattern, for example.
> I solved this by learning (by accident) of the typeof() keyword...that
> is apparently not standard. Nevertheless, it allowed me to write the
> following line of code that presumably works...if only it would
> compile.
>
> > if( dynamic_cast< typeof( item1 ) >( item2 ) );
typeof(item1) will give you the static type, not the dynamic type.
>
> Interestingly enough,
>
> > cout << dynamic_cast< typeof( item1 ) >( item2 );
>
> does compile.
Why shouldn't it?
> Neither item1 or 2 is constant, in case that would
> explain this.
>
> My second issue is that I heard MS compilers do not typeof, so I'd
> either have to steal from Boost or come up with a completely different
> way to test inheritance so it would compile on my target machine
Why do you use typeof in the first place? Just put the type of item1
directly. (Which you can deduce using template functions, for example)
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|