有无大佬来解释一下这个指针为什么可以如此直接的调用了类中的私有成员变量,看着有点懵
下面代码和运行结果:
#include <iostream>
using namespace std;
class test
{
private:
int num;
public:
test(int n) : num(n){}
};
int main()
{
test t(1024);
int* add = (int*)&t;
cout << *add << endl;
*add = 2048;
cout << *add << endl;
return 0;
}