#include <iostream>
using namespace std;
/*
练习案例1:设计立方体类 Cube
1.求出立方体的面积和体积
2.分别用全局函数和成员函数判断两个立方体是否相等
*/
class Cube{
private:
int mlength;
int mwidth;
int mheight;
public:
int getLength(int length){
mlength = length;
}
int setLength(){
return mlength;
}
int getWidth(int width){
mwidth = width;
}
int setWidth(){
return mwidth;
}
int getHeight(int height){
mheight = height;
}
int setHeight(){
return mheight;
}
int setVolume(){
return mlength*mwidth*mheight;
}
//利用成员函数判断(类里面是成员函数,类外面是全局函数)
bool isSameByClass(Cube c){
if(mheight == c.getHeight() && mwidth==c.getWidth() && mlength==c.getLength()){
return true;
}else{
return false;
}
}
};
int main(){
Cube c1;
c1.getLength(12);
c1.getWidth(2);
c1.getHeight(23);
cout<<c1.setVolume()<<endl;
Cube c2;
c2.getLength(12);
c2.getWidth(2);
c2.getHeight(23);
bool ret = c1.isSameByClass(c2);
cout<<ret<<endl;
}
运行一直显示error: no matching function for call to Cube::getHeight()