I'm studying about accessing private class members. I would like to understand better about this.
class Sharp
{
public:
Sharp();
~Sharp();
private:
DWORD dwSharp;
public:
void SetSharp( DWORD sharp ) { dwSharp = sharp; };
};
Sharp::Sharp()
{
dwSharp = 5;
}
Sharp::~Sharp()
{
}
int _tmain(int argc, _TCHAR* argv[])
{
DWORD a = 1;
*(DWORD*)&a = 3;
Sharp *pSharp = new Sharp;
cout << *(DWORD*)&pSharp[0] << endl;
cout << *(DWORD*)pSharp << endl;
cout << (DWORD*&)pSharp[0] << endl;
//pSharp = points to first object on class
//&pSharp = address where pointer is stored
//&pSharp[0] = same as pSharp
//I Would like you to correct me on these statements, thanks!
delete pSharp;
system("PAUSE");
return 0;
}
So my question is, what is pSharp,&pSharp and &pSharp[0], also please explain cout << (DWORD*&)pSharp[0] << endl; and why it outputs 0000005.
Thank you!