积木

No sub title

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  140 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

在C++的类的成员函数中,允许直接访问该类的成员对象的私有成员变量
// SmartPointerStu.cpp : Defines the entry point for the console application.
//

#include 
"stdafx.h"

//#include "SmartPointer.h"
//#include <iostream>
//using namespace std;

class CPointEx_
{
public:
    
//CPointEx_(int _x = 0, int _y = -1) : x(_x), y(_y) {}
    void SetValue(int x, int y) { this->= x, this->= y; }
    
void CallPrivateMem(const CPointEx_& AObj)
    {
        x 
= AObj.x;
        y 
= AObj.y;
    }
private:
    
int x;
    
int y;
};

int _tmain(int argc, _TCHAR* argv[])
{
    CPointEx_ theObj, theObj2;
    theObj.SetValue(
1020);
    theObj2.SetValue(
3040);
    theObj2.CallPrivateMem(theObj);


    system(
"pause");
    
return 0;
}


posted on 2011-06-29 14:41 Jacc.Kim 阅读(1446) 评论(0)  编辑 收藏 引用 所属分类: VC / C++

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