Visual C++ 说我的 void 函数需要一个返回值
我在我的 Mac 上编译了它,它运行良好,但现在我正在尝试用 Visual c++ 编译它(使用 Windows 7)
这是构建日志:
命令行 创建临时文件 "c:\Users\Jonathan\Documents\Visual Studio 2008\Projects\magicsquare\Debug\RSP00000822923000.rsp" 内容为 [ /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" / D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\" /Fd"Debug\vc90.pdb" /W3 /c /ZI /TP ".\magicsquare.cpp" ] 创建命令行 "cl.exe @"c:\Users\Jonathan\Documents\Visual Studio 2008\Projects\magicsquare\Debug\RSP00000822923000.rsp" /nologo /errorReport:prompt"
输出窗口正在编译... magicsquare.cpp c:\users\jonathan\documents\visual studio 2008\projects\magicsquare\magicsquare.cpp(224) : error C4716: 'check' : must return a value
结果 构建日志保存在“file://c:\Users\Jonathan\Documents\Visual Studio 2008\Projects\magicsquare\Debug\BuildLog.htm”magicsquare - 1 个错误,0 个警告
我的函数头和函数
void **check (int **, int);
void **check(int **matrix, int size)
{
//check if first row and last row are the same
int rsum = 0, rsum2 = 0;
bool rowflag = false;
for(int i = 0; i < size; i++)
{
rsum += *(*(matrix + 0) +i);
rsum2 += *(*(matrix + size - 1) +i);
}
//check if first column and last column are the same
int csum = 0, csum2= 0;
bool columnflag = false;
for(int i = 0; i < size; i++)
{
csum += *(*(matrix + i) + 0);
csum2 += *(*(matrix + i) + size - 1);
}
//check if diagonals are the same
int diagonal = 0, diagonal2 = 0;
bool diagonalflag = false;
for(int i = 0; i < size; i++)
diagonal += *(*(matrix + i) + i);
int m = 0;
int n = size - 1;
while (m <= size - 1)
{
diagonal2 += *(*(matrix + m) + n);
m++;
n--;
}
//if row, column, diagonal are the same
if (rsum == rsum2 && rsum2 == csum && csum == csum2 && csum2 == diagonal && diagonal == diagonal2)
cout << "This is a Magic Square\n" << endl;
else
cout << "This is not a Magic Square\n" << endl;
}
如果需要,这里是整个代码 http://pastie.org/691402