Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;课程不适合我_C++_Class_Variables_Scope - Fatal编程技术网

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)
    ,然后通过传递的引用修改变量。不过,最好对每个值使用单独的函数。