使用void定义函数后在main函数中使用,报错(错误代码:LNK2019和LNK1120)
错误 LNK2019 无法解析的外部符号 _main,函数 "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 中引用了该符号 the fourth chapter E:\visual studio\c++\the fourth chapter\the fourth chapter\MSVCRTD.lib(exe_main.obj)
void act1(int(x), int(y)) {
y = x;
printf("%d", y);
}
void act2(int(x), int(y)) {
y = 2 * x - 1;
printf("%d", y);
}
void act3(int(x), int(y)) {
y = 3 * x - 11;
printf("%d", y);
}
int mian() {
int x, y = 0;
scanf_s("%d", &x);
putchar('\n');
switch (x) {
case 0:act1(x, y); break;
case 1:
case 9:act2(x, y); break;
case 10:act3(x, y); break;
}
printf("answer is %d", y);
return 0;
}
程序无法执行
错误 LNK2019 无法解析的外部符号 _main,函数 "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 中引用了该符号 the fourth chapter E:\visual studio\c++\the fourth chapter\the fourth chapter\MSVCRTD.lib(exe_main.obj)
尝试不使用void定义的函数执行,任然报错
int mian() {
int x, y = 0;
scanf_s("%d", &x);
putchar('\n');
switch (x) {
case 0:y = x; break;
case 1:
case 9: y = 2 * x - 1; break;
case 10:y = 3 * x - 11; break;
}
printf("answer is %d", y);
return 0;
}
报错内容相同
解决问题
以上仅供参考,如有任何疑问,可以评论回复,看到即回。
希望对题主有所帮助!可以的话,帮忙点个采纳!
是main函数,不是mian函数