【发布时间】:2013-06-29 15:09:03
【问题描述】:
我知道这可能是一个非常简单的解决方法,但我很难找到我的错误所在,而且我在网上查看的所有帖子都无法帮助我。我在 cout 线上得到错误。代码如下:
#include <iostream>
bool online(int a, int network[a][a]) {
/*post condition: returns true if every switch in a network is of even degree. Otherwise, returns false.*/
int switches;
for(int x=0; x < a; x++) {
switches = 0;
for(int y=0; y < a; y++)
if(network[x][y])
switches += 1;
if(switches & 1)
return 0;
}
return 1;
}
int main() {
int arrayOne[6][6] =
{
{0,1,1,0,0,0},
{1,0,0,1,0,0},
{1,0,0,1,0,0},
{0,1,1,0,1,1},
{0,0,0,1,0,1},
{0,0,0,1,1,0}
};
int arrayTwo[8][8] =
{
{0,1,1,0,0,0,0,0},
{1,0,0,1,0,0,0,0},
{1,0,0,1,0,0,0,0},
{0,1,1,0,1,0,0,0},
{0,0,0,1,0,1,1,0},
{0,0,0,0,1,0,0,1},
{0,0,0,0,1,0,0,1},
{0,0,0,0,0,1,1,0}
};
std::cout << online(6, arrayOne) << std::endl;
std::cout << online(8, arrayTwo) << std::endl;
}
【问题讨论】:
-
我收到错误
Array has incomplete element type int '[]',是的,如果任何行中有奇数则返回 false -
请仅使用您使用的语言标记您的帖子。我将其编辑为仅
c++,如果您使用不同的语言并且我误读了您的帖子,请删除c++标签并仅输入您使用的特定语言。 -
我在同一个地方仍然遇到同样的错误。
-
我怀疑是否有任何将数组大小与参数相关联。您必须使用更抽象的数组声明。
标签: c++