2015-10-20 23 views
-3

我写了这个程序,但它不起作用。它给出了一个错误,xy没有声明和预期主要表达式行int 17之前的int。C++类不适合我

#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

+0

另外你定义一个返回类型为'的GetValue()'所以你需要就算返回一个整数,它是'return 0;' –

回答

4
  1. 参数需要具有类型C++返回2个值。写下您的shapes::decideshape作为

    void shapes::decideshape(int x, int y) 
    
  2. 你不从shapes::getvalue返回值的定义。

  3. 您将太少(实际上没有)参数传递给shapes::decideshape。预计将提供两个int s。

  4. 您需要告诉编译器函数返回明确。将int返回值添加到main

+0

非常感谢你的工作,我在getvalue中调用了decideshapes。 – Dementor

+0

我应该如何从函数getvalue返回2个值 – Dementor

+0

@Dementor是否属于同一类型?什么情况?如果还有其他问题,请在另一个线程中询问另一个问题。另外,首先显示**你的**方法。如果它不起作用,我们会帮助你。 – Downvoter

0

你缺少的xy在参数列表类型和:

void shapes::decideshape(int x, int y)