| e8555c89 Andy McCall | 1 | |
| 2 | |
|
| 3 | ||
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | // Example usage: |
|
| 8 | // class Foo { |
|
| 9 | // ... |
|
| 10 | // struct Bar : public SomeBaseClass { |
|
| 11 | // ... |
|
| 12 | // void f() override { |
|
| 13 | // // transform the 'this' pointer to the 'bar' inner object |
|
| 14 | // // into a reference to the outer object of type Foo. |
|
| 15 | // Foo& foo = OUTER(Foo, bar); |
|
| 16 | // } |
|
| 17 | // } bar; |
|
| 18 | // }; |
|
| 19 | // |
|
| 20 | // This avoids having to store a back-pointer from the inner 'bar' object to |
|
| 21 | // the outer 'Foo' object. |
|
| 22 | // |
|
| 23 | // The 'bar' object lives at a fixed offset inside the 'Foo' object, so |
|
| 24 | // changing the bar-this-pointer into a Foo-reference is a matter of |
|
| 25 | // subtracting this (compile-time-constant) offset. |
|
| 26 | // |
|
| 27 | // At least the offset is constant in the absence of virtual inheritance (we |
|
| 28 | // don't use this c++ feature in openMSX). Also strictly speaking the c++ |
|
| 29 | // standard doesn't guarantee the offset is constant in the presence of virtual |
|
| 30 | // functions, though it is in all practical implementations. See here for more |
|
| 31 | // background info: |
|
| 32 | // http://stackoverflow.com/questions/1129894/why-cant-you-use-offsetof-on-non-pod-structures-in-c |
|
| 33 | |
|
| 34 | ||
| 35 | // Adjust the current 'this' pointer (pointer to the inner object) to a |
|
| 36 | // reference to the outer object. The first parameter is the type of the outer |
|
| 37 | // object, the second parameter is the name of the 'this' member variable in |
|
| 38 | // the outer object. |
|
| 39 | |
|
| 40 | int |
|
| 41 | ||
| 42 | |
|
| 43 | |
|
| 44 | ||
| 45 | |