【发布时间】:2015-10-20 08:26:22
【问题描述】:
我已经编写了这个程序,但它不起作用。它给出了一个错误,即 x 和 y 未声明,并且在 17 行之前的 int 预期主表达式。
#include<iostream>
using namespace std;
class shapes
{
int width, height;
public:
int getvalue();
void decideshape(int l, int b);
};
main()
{
cout<<"to find what type of shape you have input the measurements"<<endl;
shapes toy;
toy.getvalue();
toy.decideshape();
}
int shapes::getvalue()
{
int l, b;
cout<<"length = ";
cin>>l;
cout<<"breath = ";
cin>>b;
}
void shapes::decideshape(x, y)
{
if(x==y)
cout<<"This is square"<<endl;
else
cout<<"This is rectangle"<<endl;
}
我应该如何从函数 getvalue 中返回 2 个值
【问题讨论】:
-
另外你定义了
getvalue()的返回类型,所以你需要返回一个整数,即使它是return 0;