2015-10-20 54 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)