// class2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<string.h>
#include <iostream>
using namespace std;
class CPoint
{
public:
CPoint (int x,int y){
nPosX =x;nPosY = y;
}
void ShowPos(){
cout<<"当前位置:x="<<nPosX<<",y="<<nPosY<<endl;
}
private:
int nPosX;int nPosY;
};
class CSize{
public:
CSize(int l, int w)
{
nLength = 1;nWidth = w;
}
void ShowSize(){
cout<<"当前大小:l="<<nLength<<",w = "<< nWidth<<endl;
}
private:
int nLength ,nWidth;
};
class CRect
{
public:
CRect (int left,int top, int right,int bottom );
void Show(){
ptCenter.ShowPos();
size.ShowSize();
}
private:
CPoint ptCenter;
CSize size;
};
CRect ::CRect (int left,int top,int right,int bottom)
:size(right -left,bottom -top),ptCenter((left+right)/2,(top+bottom)/2)
{}
int _tmain(int argc, _TCHAR* argv[])
{
CRect rc(10,100,80,250);
rc.Show();
return 0;
}
在这段代码中void Show(){
ptCenter.ShowPos();
size.ShowSize();
}的ptCenter怎么知道是属于哪一个类的??只有一个调用类的成员函数就知道是该类的对象了么??
如果有关成员函数的详细资料的就更好了!! |