注册 登录
编程论坛 C++教室

无法理解对像的定义:对像名.函数成员名

qinshufa2010 发布于 2014-06-23 19:07, 469 次点击
大家好,Visual C 6.0中对像的定义如何理解?如  对像名.函数成员名  
具体的例子   如下的ptCenter.ShowPos()如何理解呢,请各们高手指教。
#include <iostream.h>
class CPoint
{
public:
   CPoint(int x,int y){
   nPosX=x;  nPosY=y;
   cout<<"CPoint类构造函数"《end1;
}
void ShowPos() {
  cout<<"当前位置:x="<<nPosX<<",y="<<nPosY<<end1;
}
Private
int nPosX,nPosY;
}

Class CRect
{
public:
CRect(int left,int top,int bottom,int right);
void Show() {
ptCenter.ShowPos();
}
private:
CPoint ptCenter;
}
CRect::CRect(int left,int top,int bottom,int right):size(right-left,bottom-top),ptCenter((left+right)/2,(top+bottom)/2
{}
void main()
{
CRect rc(10,120,70,230);
rc.Show();
}
2 回复
#2
pauljames2014-06-23 19:24
对象你理解成一个结构体就好了,只是这个结构体里面有数据也有函数指针
#3
代码95272014-06-29 00:37
对象名就是你的名字,成员函数就是你的嘴巴,鼻子等,你可以调用你的嘴巴吃饭,用鼻子呼吸
1