【问题标题】:Why is visual C++ giving me this error?为什么 Visual C++ 给我这个错误?
【发布时间】:2015-06-25 08:19:44
【问题描述】:

所以我不知道为什么我会在我标记的行显示“错误:类型为“颜色”的参数与类型为“颜色(*)[2]”的参数不兼容

p>
#include <iostream>

using namespace std;

enum color{black, white};

bool negative(color a[2][2], color b[2][2]);
void main(){

color a[2][2] = { { black, white }, { white, black } };
color b[2][2] = { { white, black }, { black, white } };
negative(a[2][2], b[2][2]);  //<==== here (under "a" and "b")

}

bool negative(color a[2][2], color b[2][2]){
int False=0, True=0;
    for (int i = 0; i < 2; i++){
    for (int j = 0; j < 2; j++){
        if (a[i][j] != b[i][j]) True++;
        else False++;
    }
}
    if (True == 2 && False == 0)return true;
    else if (True == 0 && False == 2)return false;

}

【问题讨论】:

  • 拜托,拜托,请写一个更好的标题。我通常会跳过标题不具描述性的问题。
  • 这样调用你的函数:negative(a, b);

标签: c++ enums


【解决方案1】:

negative 函数接受由 color 参数组成的数组数组,但您传递了一个单个 color 值,该值也超出了数组的范围。

调用为

negative(a, b);

我建议你回到你的书或教程,阅读更多关于数组的内容。

【讨论】:

    【解决方案2】:

    您的问题是您应该传递一个数组,但您却试图传递一个元素(甚至不存在)。

    当你这样做时

    a[2][2] 您描述了数组的第三行第三列(如果您将二维数组视为表格)元素。

     negative(a,b)
    

    是你可能想要做的。

    【讨论】:

      猜你喜欢
      • 2011-09-07
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      • 2012-04-25
      • 2013-11-14
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      相关资源
      最近更新 更多