C++ 代码错误
C++ Error with code
我目前正在学习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;
}
这意味着,作为populateStock
参数传递的内容不是它所采用的参数类型。它需要不同类型的参数。由于您没有发布函数代码populateStock
我无法准确地指出您,但这是我能告诉您的最好的。
从你的函数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);
相关文章:
- 错误处理.将系统错误代码映射到泛型
- 为什么我在使用void函数时得到错误代码C2276
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- 逻辑运算符上出现错误代码 a')'
- 'val' Arduino 错误代码之前的预期'('
- 我在贪吃蛇游戏中收到了错误代码 -1073741571
- 根据 GetLastError 直接写入磁盘会导致错误代码 5
- 当我选择大于 720 的矩阵大小时,程序退出并显示错误代码.可能是什么原因?
- 创建进程 API 失败,在窗口 122 上出现错误代码 10
- 使用另一个函数调用一个函数(都在类中)时出现问题.没有错误代码C++
- 当命令失败时,gzip 会在 C++ 中返回错误代码吗?
- 从 C++ 调用 cURL 命令会返回意外的错误代码,如 1792 和 6656
- WSALookupServiceBegin() 上的错误代码 10022(无效的 arugment)
- C++ Schannel POST 400 错误代码错误请求
- openCL-创建子缓冲区返回错误代码13
- 更新了Runge-Kutta(RK4)C++错误代码中的二阶DE
- 获取有关使用未初始化内存的错误代码
- 排序程序的意外错误代码
- 正在将DJI错误代码记录到流中
- 来自API的错误代码..处理什么是好的做法