casting - C++ - downcasting a diamond shape inherited object without RTTI/dynamic_cast -


I am currently working on integrating a third-party package which is available on many non-RTTI platforms with a lot of RTTI Uses accessories (android). Actually, I implemented my own RTTI, but I got stuck on a problem.

The issue is that there is a diamond legacy problem in many sections because all the classes are the same base class .. And so, if I want to make the class derived from the base class, Use a dynamic_cast - but RTTI is not available! How can I convert the object from child to originals when I have a virtual legacy without dynamic_cast?

It looks like:

  class A {public: virtual char * func} {return "A"; }; }; Class B: Public Virtual A {Public: // Virtual Variable * func () {Return "B"; }; }; Class C: Public Virtual A {Public: // Virtual Variable * func () {Return "C"; }; }; Category D: Public B, Public C {Public: // Virtual Variable * func () {Return "D"; }; }; DD; A * PA = Static_cast & lt; A * & gt; (& Amp; D); D * PD = Static_cast & lt; D *> (PA); // can not do it! Dynamic_cast works though ...  

These are my errors:

Error C2635: 'A *' has not been changed to 'D *' Can go; Conversion is implied with a virtual base class

Error C2440: 'Start': 'test_convert :: A *' to 'test_convert :: D *' not changed to be taken from the base to be replaced Can dynamic_cast be required or static_cast

Any ideas?

You only dynamic_cast with this artist; No other artist will do this.

If you can not design your interface, then you do not need to cast this type of thing, so whatever you can do is part of your casting functionality, the class hierarchy.

Example (badly hacked)

  class D; Class A {Public: Virtual D * GetDPtr () {Return 0; }}; Class B: Public Virtual A {}; Class C: Public Virtual A {}; Class D: Public B, Public C {Public: Virtual D * GetDPtr ()} This Return; }};  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -