fork download
  1. #include <stdio.h>
  2. #include <stddef.h>
  3.  
  4. template< int base_offs > struct pin {
  5. int y1;
  6. void test( void );
  7. };
  8.  
  9. template< class pin1, class pin2 > struct wrap0 {
  10. int x1;
  11. char x2;
  12. pin1 r3;
  13. pin2 r4;
  14. };
  15.  
  16. template< int base_offs >
  17. void pin<base_offs>::test( void ) {
  18. typedef wrap0< pin<0>,pin<0> > wrap;
  19. wrap& W = *(wrap*)(((char*)this)-base_offs);
  20. printf( "y1=%i W.x1=%i W.x2=%i\n", y1, W.x1, W.x2 );
  21. }
  22.  
  23. typedef wrap0< pin<0>,pin<0> > wrap1;
  24.  
  25. typedef wrap0< pin< offsetof(wrap1,r3) >, pin< offsetof(wrap1,r4) > > wrap;
  26.  
  27. wrap Z = {456,123,33333,44444};
  28.  
  29. int main( void ) {
  30. Z.r3.test();
  31. Z.r4.test();
  32. }
  33.  
  34.  
  35.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
y1=33333 W.x1=456 W.x2=123
y1=44444 W.x1=456 W.x2=123