Connecting Tech Pros Worldwide Forums | Help | Site Map

virtual casting ?

Herby
Guest
 
Posts: n/a
#1: Mar 27 '06
Given classes B and C iinherit from class A.
B and C override a method of the form:
Add( A^ lhs, A^ rhs ); So A is abstract.

So if i was defining Add for class B :

B::Add( A^ lhs, A^ rhs )
{
Value = ((B)lhs)->Value + ((B)rhs)->Value;
}

And the rhs argument happens to be of type C, although mostly it would
be of type B.
Instances of type C can legally be cast( converted ) to instances of
type B.

Given the argument is of type A, and the actual instance can be either
B or C.
How can i cast rhs to B?

I tried adding a virtual and concrete operatorB*() to A and C,
but made no difference?

Any ideas greatly appreciated?


Closed Thread


Similar .NET Framework bytes