class Register
{
private:
DWORD ax,dx,cx,bx; // POH
DWORD bp,sp;
DWORD flag, ip;
public:
//====================================================
Register()
{
ax = 0x0;
dx = 0x0;
cx = 0x0;
bx = 0x0;
bp = 0x0;
//memset(&this->sp,0,sizeof(sp));
sp = 0x0;
flag = 0x0;
ip = 0x0;
}
//====================================================
~Register()
{
}
//====================================================
void setAx(DWORD d)
{
ax=d;
}
//====================================================
DWORD getSp()
{
return sp;
}
}*PReg;
Why does function getSp(); gives an Access Violation error?
You have forgotten to instantiate your class. You have made a variable that is a pointer to the class Register, but you have not instantiated it.
What you get is a pointer that is either null or pointing to some random memory location, and you are assuming that it is pointing to your instance of the class. So when you try to access any of the member variables your are actually accessing memory locations you do not have access to.
What you need to do is create a new instance of the class:
May I at the same time suggest that you move the variable declaration away from the class prototype (which I assume resides in your header file).