#include<iostream>
using namespace std;
class point
{
private:
int x;
int y;
public:
point(){}
point(int a,int b)
{
x=a;
y=b;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
};
class rect
{
private:
point p1,p2;
public:
int length,width;
void setvalue()
{
int a1,b1,a2,b2;
cout<<"请输入第一个点的数据:x,y:";
cin>>a1>>b1;
p1=point(a1,b1);
cout<<"请输入第二个点的数据:x,y:";
cin>>a2>>b2;
p2=point(a2,b2);
}
length=p1.getX()-p2.getX();
width=p1.getY()-p2.getY();
};
int main()
{
rect rec1;
rec1.setvalue();
int area;
area=length*width;
cout<<area;
return 0;
}
创建point类和rect类,rect类有两个point类对象p1,p2私有成员,但是编译时出现错误:
'rect::p1' : member from enclosing class is not a type name, static, or enumerator
f:\c++6.0\microsoft visual studio\myprojects\test1\test1.cpp(40) : error C2065: 'p1' : undeclared identifier
f:\c++6.0\microsoft visual studio\myprojects\test1\test1.cpp(40) : error C2228: left of '.getX' must have class/struct/union type
交互式爱情
30秒到达战场
相关分类