我目前正在学习C ++并且有一个程序,这个代码运行正常。我将这个代码从我的第一个程序复制到我的第二个程序中,但我无法弄清楚导致错误的原因。错误为“错误:StudentResults
的参数类型与StudentResults
代码如下,我知道其中一些被引用,这只是为了阻止一些工作,直到我得到这个错误排序。这只是我认为错误所在的代码示例,如果需要更多代码,我将添加其余代码。错误是** **的位置,这些实际上并不在代码中,只是为了突出显示错误的位置。感谢
//Prototypes - common
void press_key(HANDLE hdl, int col, int row);
void message(HANDLE hdl, char mess[], int col, int row);
char again(HANDLE hdl, int col, int row);
void set_menu(HANDLE hdl );
int get_option(HANDLE hdl, int c , int r , int min , int max);
void gotoXY( HANDLE hdl, SHORT x, SHORT y );
void clrScr(HANDLE hdl );
void getscreen(HANDLE hdl, char name[]);
void validateString(HANDLE hdl, int col, int row, int min, int max,char str[], char errMessage[]);
int validateNumber(HANDLE hdl, int col, int row, int min, int max, char errMessage[]);
//prototypes - menu
int populateStock( struct StudentDetails student_details[]);
void reportResults(HANDLE hdl, struct StudentDetails student_details[], int size);
void displayBySurname(HANDLE hdl,struct StudentDetails student_details[], int size);
void displayByStudentNumber(HANDLE hdl, struct StudentDetails student_details[30], int size);
void updateStock(HANDLE hdl, struct StudentDetails student_details[], int size );
void addStock(HANDLE hdl, struct StudentDetails student_details[], int & size);
struct StudentResults
{
int candidateNo;
char forename[20], surname[20];
int section[5];
};
int _tmain(int argc, _TCHAR* argv[])
{
// insert HANDLE hdl
HANDLE hdl = GetStdHandle( STD_OUTPUT_HANDLE );
//Data Declaration
int option, size;
struct StudentResults student_details[30] ;
// fill array with some stock details
size = populateStock(student_details); // error here
do
{
set_menu(hdl);
option=get_option(hdl, 44,20,1,7);
switch(option)
{
case 1:; //reportStock(hdl, student_details, size);
case 2:; //displayStockByCat(hdl, student_details, size);
case 3:; //searchStock(hdl, stock_details, size);
case 4:; //searchStockByDesc(hdl, stock_details, size);
case 5:; //updateStock(hdl, stock_details,size);
case 6:; //addStock(hdl, stock_details,size);
}
} while (option !=7);
return 0;
}
int populateStock( struct StudentResults student_details[])
{
int size;
student_details[0].candidateNo = 1004;
strcpy_s(student_details[0].forename , "Joe");
strcpy_s(student_details[0].surname , "Bloggs");
student_details[0].section[0] = 20.87;
student_details[0].section[1] = 20.87;
student_details[0].section[2] = 20.87;
student_details[0].section[3] = 20.87;
student_details[0].section[4] = 20.87;
return 1;
}
答案 0 :(得分:1)
这意味着,作为populateStock
参数传递的内容不是它所采用的参数类型。它需要不同类型的参数。由于你没有发布功能代码populateStock
,我无法准确指出你,但这是我能告诉你的最好的。
答案 1 :(得分:0)
从您的函数populateStock
定义:
int populateStock( struct StudentDetails student_details[]);
populateStock
正在接受struct StudentDetails
作为参数类型,但您传递的是类型为struct StudentResults
的对象,这是一种不兼容的类型。
struct StudentResults student_details[30] ;
// fill array with some stock details
/*This will generate an error as your passing an incompatible type */
size = populateStock(student_details);