It is called pointer to member
. It allows you to approach member variables in a roundabout way.
For more information, I have added more code below and annotated it.
#include <iostream>
using namespace std;
class Car
{
public:
int speed;
};
int main()
{
int Car::*pSpeed = &Car::speed;
Car c1;
c1.speed = 1; // Direct access (typical)
cout << "speed is" << c1.speed << endl; //1 output
c1.*pSpeed = 2; // use pointer to member to approach (pass)
cout << "speed is" << c1.speed << endl; //2 output
return 0;
}
I only know it as a theory, but I've never actually written it.
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.