posts - 28,  comments - 15,  trackbacks - 0

为了获取Class的private成员的数据---int* flag = (int*)(ctest);

#include<iostream>
class CTest
{
private:
 int m_y;
public:
 CTest(int value){m_y = value;}
 ~CTest(){}
 void getValue(){std::cout<<"m_y is: "<<m_y<<std::endl;}
};

void getClassValue(CTest* ctest)
{
 //for(int* flag = (int*)(ctest);*flag!=NULL;flag++)

  int* flag = (int*)(ctest);
        std::cout<<*flag<<std::endl;
        //flag++;
        std::cout<<*(++flag)<<std::endl;

//这里同时也反映出++i和i++的区别
  std::cout<<*flag<<std::endl;
}


int _tmain(int argc, _TCHAR* argv[])
{
 CTest* test=new CTest(2);
 test->getValue();
 getClassValue(test);
 delete test;
 system("pause");
 return 0;
}

posted on 2009-08-22 18:52 闫军yy 阅读(414) 评论(0)  编辑 收藏 引用 所属分类: c++/c

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理