Adobe笔试题……
题目:
#include<iostream>
#include<string>
using namespace std;
class person
{
private:
string name;
int age;
public:
person(string n, int a): name(n), age(a)
{}
};
person hacker("John", 25);
问如何访问hacker的私有属性
答案:
class personMirror
{
public:
string name;
int age;
personMirror(string n, int a): name(n), age(a)
{}
};
int main()
{
person p("Join",22);
personMirror* pM = reinterpret_cast<personMirror*>(&p);
cout << pM->name << "---"<< pM->age << endl;
return 0;
}