Adobe笔试题……

来源:互联网 发布:阿里云 系统盘 编辑:程序博客网 时间:2024/05/01 07:09

 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;
}