环境:visual studio 2008
#include "StdAfx.h"
#include<iostream>
#include<cmath>
using namespace std;
class Point
{
public:
void InitP(float xx=0,float yy=0){X=xx;Y=yy;}
void Move(float xOff,float yOff){X+=xOff;Y+=yOff;}
float GetX(){return X;}
float GetY(){return Y;}
private:
float X,Y;
};
class Rectangle:private Point
{
public:
void InitR(float x,float y,float w,float h)
{InitP(x,y);W=w;H=h;}
void Move(float xOff,float yOff){Point::move(xOff,yOff);}
float GetX(){return Point::GetX();}
float GetY(){return Point::GetY();}
float GetH(){return H;}
float GetW(){return W;}
private:
float W,H;
};
int main()
{
Rectangle rect;
rect.InitR(2,3,20,10);
rect.Move(3,2);
cout<<"The data of rect(X,Y,W,H):"<<endl;
cout<<rect.GetX()<<","<<rect.GetX()<<","<<rect.GetW()<<","<<rect.GetH()<<","<<endl;
getchar();
}
正常
把Point::move(xOff,yOff);改为move(xOff,yOff);后
#include "StdAfx.h"
#include<iostream>
#include<cmath>
using namespace std;
class Point
{
public:
void InitP(float xx=0,float yy=0){X=xx;Y=yy;}
void Move(float xOff,float yOff){X+=xOff;Y+=yOff;}
float GetX(){return X;}
float GetY(){return Y;}
private:
float X,Y;
};
class Rectangle:private Point
{
public:
void InitR(float x,float y,float w,float h)
{InitP(x,y);W=w;H=h;}
void Move(float xOff,float yOff){Move(xOff,yOff);}
float GetX(){return Point::GetX();}
float GetY(){return Point::GetY();}
float GetH(){return H;}
float GetW(){return W;}
private:
float W,H;
};
int main()
{
Rectangle rect;
rect.InitR(2,3,20,10);
rect.Move(3,2);
cout<<"The data of rect(X,Y,W,H):"<<endl;
cout<<rect.GetX()<<","<<rect.GetX()<<","<<rect.GetW()<<","<<rect.GetH()<<","<<endl;
getchar();
}
point.exe 中的 0x013a1849 处未处理的异常: 0xC00000FD: Stack overflow