I'd like to compose member pointers. Basically I have a main class with different member. How do I create a member pointer for the main class that would point to a member of a member of that class. I hope the code below is explains what I'm trying to do:
  struct SubUnit
  {
    int   value;
  };
  struct Unit
  {
    SubUnit sub_unit;
  };
  void Test()
  {
    SubUnit Unit::* ptr1 = &Unit::sub_unit; // WORKING
    int Unit::* ptr2 = &Unit::sub_unit::value; // NOT WORKING !
  }
                It seems you have to do it in two phases:
SubUnit Unit::*pSub = &Unit::sub_unit;
int SubUnit::*pValue = &SubUnit::value;
Unit u;
int theVal = (u.*pSub).*pValue;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With