64,648
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include<string>
using namespace std;
class Point
{
//friend class v;
public:
Point(const string &ss, const int &ii) :m_nPointCount(ii),s(ss)
{
//m_nPointCount++;
}
~Point()
{
//m_nPointCount--;
}
private:
int m_nPointCount = 0;
string s = "world";
};
class v{
public:
v(const string &ss, const int &ii) :m_nPointCount(ii), s(ss)
{
//m_nPointCount++;
}
~v()
{
//m_nPointCount--;
}
public:
int m_nPointCount = 0;
string s = "world";
};
void main()
{
Point vv("leee",0);
v aa("leee", 0);
cout << *(string*)((Point*)(&vv) + ((v*)(&aa.s) - (v*)(&aa))) << endl;
}
这样做有什么意义呢?在项目中出现这样的代码有可能会被XX的
要走正道,这种方式不可取。