fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct customType {
  5. int b;
  6. };
  7. struct Instruction {};
  8.  
  9. class BasicBlock {
  10. public:
  11.  
  12. BasicBlock(int a) { InstList.b = a; }
  13. customType InstList;
  14.  
  15. static customType BasicBlock::*getSublistAccess(Instruction*) {
  16. return &BasicBlock::InstList;
  17. }
  18. };
  19.  
  20. int main() {
  21.  
  22. BasicBlock bb(90);
  23.  
  24. Instruction justForSignature;
  25. // Get a pointer to a member of type customType through the static function
  26. customType BasicBlock::* ptrToMember = BasicBlock::getSublistAccess(&justForSignature);
  27.  
  28. cout << (bb.*ptrToMember).b; // Parenthesis are necessary, '.' has higher precedence on *
  29. // Output: 90
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
90