2013-06-29 78 views
2

我知道這可能是一個非常簡單的修復,但我很難找到我的錯誤是什麼,也沒有任何我在網上查過的帖子能夠幫我。我得到了關於線路的錯誤。下面的代碼:錯誤:沒有匹配函數調用'在線'

#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; 
}  
+0

我得到的錯誤'陣列具有不完整的元素類型爲int「[]」',是的,意圖是返回false,如果有任何行奇數 – Dbz

+1

請只用語言標記您的文章你正在使用。我將它編輯爲'C++',如果您使用的是其他語言,並且我誤讀了您的帖子,請刪除'C++'標籤,並僅使用您正在使用的特定語言。 – mcmonkey4eva

+0

我仍然在同一個地方得到相同的錯誤。 – Dbz

回答

4

對於C99(支持可變長度數組),也沒有<iostream>。確保你編譯的程序是C而不是C++,然後用<stdio.h>代替,並且包括<stdbool.h>

printf("%d\n", online(6, arrayOne)); 
printf("%d\n", online(8, arrayTwo)); 

對於C++,編譯器可能不支持可變長度數組。您應該使用模板來代替online()

template <unsigned a> 
bool online(int, int (&network)[a][a]) { 
    //... 
} 
+0

只是關於你的第一句話的問題。 C99是否支持二維長度可變的數組? –

+0

去jxh的路。你解決了它!有沒有辦法讓函數不傳遞一個int大小? – Dbz

+0

@MartinR:AFAIK,是的。 – jxh

相關問題