|
Re: Your C++ Wish List (Editorial)
|
Posted: Oct 10, 2008 12:21 PM
|
|
Thanks a lot for your reply lemon head, and nice trick.
I saw also some pages discussing the difference between CRTP and barton-nackmann's trick.
I'll analyze it depth but it seems that it isn't what I was looking for: I'd prefer to avoid the inversion "nested object" to "parent class". Despite, I thought of using it with several nested classes/structs, so I'd say that that rules out this approach.
Maybe storing a pointer to 'this' is the only safe way to do this; which is, put it simply, what Java does.
I'm also considering some way of calculating outer's 'this' from within the nested class. In principle having nested's 'this' and the field offset it could be achieved. Something like
(Within nested) reinterpret_cast<OuterType*>(this - nested field offset within outer);
But I believe that it could be, so to say, very dangerous. In some webpages a way to calculate the offset is proposed, but it involves dereferencing 0.
At last, see that you used extends in the C++ example (Outside class definition).
Thanks again, cheers.
Rodolfo
|
|