Answer the question
In order to leave comments, you need to log in
How to cast an object to a higher type in the inheritance tree?
If I have a FileMember class inherited from Grid, I can cast it to Grid without any problems, but I need it the other way around, there is a Grid and I need to cast it to FileMember. The latter does not have a constructor.
Answer the question
In order to leave comments, you need to log in
You will have to make a constructor in FileMember that will take a Grid and build itself based on it. In this case, the connection with the original object will be lost (if critical).
Alternatively, you can remove the inheritance and make FileMember a property that accepts Grid . It will be easier to pass a Grid to a FileMember :) But FileMember will have to be tweaked a lot to make it behave like a Grid . In fact, there will be a stupid redirect (but pitfalls cannot be ruled out, everything can be more complicated).
In the end, you need to choose what will be easier: copy the original Grid to FileMember; or define all properties, methods of Grid , etc. in FileMember ; or abandon the idea of passing Grid , use only FileMember , change the original task to a variant with a simpler solution.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question