I am developing a driver for a piece of memory mapped hardware using C++ and I defined a class that represents this device. It looks something like this:
class device
{
method1();
method2();
private:
device_register reg1;
device_register reg2;
}
The class has two files: device.cpp and device.h. The member variables represent actual registers on the device itself. Now I want to define more members that are not actual registers on the device itself, but I cannot define them inside the class because if I do, they will be defined at the memory mapped location of the device, which could contain other devices/registers. if I define them as public, that breaks the standard layout and the class won't work anymore.
So what I did is that I defined them as global variables outside the class definition. The problem is if I define more than one object, they will all share these global variables, but I want each object to have its own, how can I do this?