刘收获

导航

访问class中的保护对象的方法

#include <windows.h>
#include <iostream>

using namespace std;

DWORD WINAPI ThreadProc(LPVOID Param);

class MyClass
{
public:
MyClass()
{
m_1 = 10;
m_2 = 20;
m_3 = -30;
}
int m_1;

int GetMember()
{
return m_3;
}
protected:
int m_2;
private:
int m_3;
};

int main()
{

MyClass Object;


HANDLE ThreadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, &Object, 0, NULL);

 

WaitForSingleObject(ThreadHandle, INFINITE);
return 0;
}


DWORD WINAPI ThreadProc(LPVOID Param)
{

printf("%d\r\n", ((MyClass*)Param)->m_1);
printf("%d\r\n", *((int*)Param + 1)); //方法1.通过暴力内存
printf("%d\r\n", ((MyClass*)Param)->GetMember());//方法2.提供read的接口函数

return 0;
}

posted on 2016-09-20 23:37  沉疴  阅读(161)  评论(0编辑  收藏  举报