By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

Casting operators

P: n/a
Given class B C and D all inherit from class A
They all override a method of the form:
Add( A^ lhs, A^ rhs );

But only specific conversions are allowed
So if i was defining Add for class D :

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

}

Ony C can be converted to type D and D itself.
Most of the time the arguments will be of type D itself.

How can i specify C can be cast to D ?
So C will intermediately convert itself to D.
But the others cannot.

How much overhead in terms of performance is this costing when
converting a C to a D
and when converting a D to itself?

Should i use safe_cast ?

Mar 23 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Can someone help me on this?

I thought maybe the only way to do it is in class A
provide a virtual cast operator for D^

Then C would override this and provide an implementation to convert
itself to D^

I tried this and it does not seem to work virtually?

How can this be done?

Mar 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.