2017-02-24 119 views
0

當運行下面的代碼時,我收到一個錯誤,說「形狀」不是類型名稱。誰能幫忙?類型枚舉變量不是類型名稱?

#include <iostream> 

using namespace std; 

enum triangleType {scalene, isosceles, equilateral, noTriangle};  //Define an enumeration of possible triangle types 
triangleType shape; 

shape triangleShape(int a, int b, int c); //Declare prototype for function that calculates triangle type and returns enumeration 

int main() 
{  
    return 0; 
} 
+5

'shape'是一個變量,其類型爲'triangleType',它不是一個類型名稱。 – Barmar

+0

啊,我明白了。那麼函數應該返回什麼? triangleType? – Froobyflake

+0

是的,這是類型名稱。 – Barmar

回答

0

這應該與錯誤信息解決您的問題:

enum triangleType {scalene, isosceles, equilateral, noTriangle}; 
// triangleType shape; // shape here is a declared variable of type triangleType. 

// triangleType is the type which is an enumerated type or integral type so this is valid. 
triangleType triangleShape(int a, int b, int c); 
// having a function to return a variable and not a type will generate an error 
// shape triangleShape(int a, int b, int c); // error - shape is not declared as type. 

int main() 
{  
    return 0; 
}