C++ c++;课程不适合我
我写了这个程序,但它不工作。它给出了一个错误,C++ c++;课程不适合我,c++,class,variables,scope,C++,Class,Variables,Scope,我写了这个程序,但它不工作。它给出了一个错误,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 sh
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;
}
#包括
使用名称空间std;
类形状
{
int宽度、高度;
公众:
int getvalue();
无效十字形(整数l,整数b);
};
main()
{
库特
<> >参数需要在C++中有类型。写出您的代码>形状的定义::
void shapes::decideshape(int x, int y)
您不会从shapes::getvalue
返回值
向shapes::decideshape
传递的参数太少(实际上没有)。需要提供两个int
s
您需要明确地告诉编译器函数返回的是什么。将int
返回值添加到main
参数列表中缺少x
和y
的类型:
void shapes::decideshape(int x, int y)
还可以为getvalue()定义返回类型
所以您需要返回一个整数,即使它是返回0;
非常感谢您,我在getvalue中调用了decideshapes。如何从函数中返回2个值getvalue@Dementor相同类型?什么情况下?如果你有其他问题,请在单独的线程中询问另一个问题。此外,首先展示你的方法。我们将向他提问如果它不起作用,请输入lp。同一类型,我想将长度和呼吸从getvalues()返回到main,或直接返回到decideshape()function@Dementor您可以声明/定义void shapes::getvalue(int&length,int&breath)
,然后通过传递的引用修改变量。不过,最好对每个值使用单独的函数。