2016-12-02 68 views
0

我對這個錯誤的理解是原型和頭文件中的參數與頭文件中的參數不匹配,但是在我的代碼中這些東西匹配。我不確定我在這裏錯過了什麼?錯誤「showInfo(info,SIZE);」「沒有過載函數的實例」

#include <iostream> 
#include <iomanip> 
#include <string> 
using namespace std; 

const int SIZE = 3; 
int main(); 
void showInfo(Author info[], const int &); 


struct BookInfo 
{ 
    string title; 
    double price; 
}; 


struct Author 
{ 
    string name; 
    BookInfo books[SIZE]; 
}; 


int main() 
{ 
    Author info[] = { {"NONE", {{"NONE", 0.00}, {"NONE", 0.00}, {"NONE",  0.00}}}, 
        {"NONE", {{"NONE", 0.00}, {"NONE", 0.00}, {"NONE", 0.00}}}, 
        {"NONE", {{"NONE", 0.00}, {"NONE", 0.00}, {"NONE", 0.00}}}, 
       }; 
showInfo(info,SIZE); 
return 0; 
} 

void showInfo(Author info[], const int&) 
{ 
    for (int i = 0; i < SIZE; i++) 
    { 
     cout << info[i].name << endl; 
     for (int j = 0; j < SIZE; j++) 
    { 
     cout << info[i].books[j].title << endl; 
     cout << info[i].books[j].price << endl; 
    } 
    } 
} 

回答

1

不,這些東西實際上不匹配。

showInfo()的第二個參數是對可變整數的引用。

您正在嘗試傳遞const整數的引用:const int SIZE

showInfo的第2參數更改爲const int &。實際上,它可能只是一個普通的int。我不明白在這裏如何傳遞引用可以實現任何有用的功能。

+0

這將錯誤更改爲「類型名稱不允許」 – Nick5227

+0

您必須犯了一個錯誤。隨意發佈另一個問題,顯示您的代碼的新版本。 –

+0

我會更新我原來的帖子,不想再重複提問帶上stackoverflow! – Nick5227

相關問題