我对这个错误的理解是原型和标题中的参数与标题的参数不匹配,但是在我的代码中这些东西是匹配的。我不确定我在这里缺少什么? “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;
}
}
}
答案 0 :(得分:1)
不,实际上那些东西不匹配。
showInfo()
的第二个参数是对可变整数的引用。
您尝试传递对const
整数的引用:const int SIZE
。
将showInfo
的第二个参数更改为const int &
。实际上,不妨让它成为普通的int
。我不知道如何通过这里的引用来完成任何有用的东西。