fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Car
  5. {
  6. public:
  7. int speed;
  8. };
  9.  
  10. int main()
  11. {
  12. int Car::*pSpeed = &Car::speed;
  13.  
  14. Car c1;
  15. c1.speed = 1; // direct access
  16. cout << "speed is " << c1.speed << endl;
  17. c1.*pSpeed = 2; // access via pointer to member
  18. cout << "speed is " << c1.speed << endl;
  19. return 0;
  20. }
Success #stdin #stdout 0s 4320KB
stdin
Standard input is empty
stdout
speed is 1
speed is 2