注册 登录
编程论坛 新人交流区

VC++2005使函数返回值为枚举变量或自定义类时编译器报错

amylit 发布于 2007-11-14 20:19, 1009 次点击

VC++2005使函数返回值为枚举变量或自定义类时编译器提示缺少类型说明符
代码:
#include "stdafx.h"
#include <iostream>

using namespace std;

enum ERR_CODE { SUCCESS, ERROR };

ERR_CODE Factor(int, int&, int&);

int _tmain(int argc, _TCHAR* argv[])
{
int number, squared, cubed;
ERR_CODE result;

cout << "Enmber a number (0 - 20): ";
cin >> number;

result = Factor(number, squared, cubed);

if (result == SUCCESS)
{
cout << "number: " << number << endl;
cout << "squared: " << squared << endl;
cout << "cubed: " << cubed << endl;
}
else
cout << "Error encountered!!" << endl;

char v;
cin >> v;

return 0;
}

ERR_COED Factor(int n, int &rSquared, int &rCubed)
{
if (n > 20)
return ERROR;
else
{
rSquared = n*n;
rCubed = n*n*n;
return SUCCESS;
}
}

编译器提示:error C2146: 语法错误 : 缺少“;”(在标识符“Factor”的前面)
缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

这是什么问题?

2 回复
#2
tlk2007-11-14 20:34
回复:(amylit)VC++2005使函数返回值为枚举变量或自...
好啊
#3
tlk2007-11-14 20:35
回复:(amylit)VC++2005使函数返回值为枚举变量或自...
学习
1