无法解析的外部符号-如何修复
Unresolved External Symbol - How to fix?
我对编程很陌生。我遇到了这个我无法解决的错误。你应该可以输入一个分数,它会使用预先放入数组中的信息,告诉你有多少学生得到了那个分数。
我得到的错误信息是:1>------ Build started: Project: Ch11_27, Configuration: Debug Win32 ------
1>Build started 4/4/2013 1:17:26 PM.
1>InitializeBuildStatus:
1> Touching "DebugCh11_27.unsuccessfulbuild".
1>ClCompile:
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl checkScore(int * const,int * const)" (?checkScore@@YAXQAH0@Z) referenced in function _main
1>F:a School Stuff TJC Spring 2013Intro ProgC++ ProjectsCh11_27DebugCh11_27.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
下面是我的代码:
//Advanced27.cpp - displays the number of students
//earning a specific score
//Created/revised by <your name> on <current date>
#include <iostream>
using namespace std;
//Function Prototypes
void checkScore( int scores[], int storage[]);
int main()
{
//declare array
int scores[20] = {90, 54, 23, 75, 67, 89, 99, 100, 34, 99,
97, 76, 73, 72, 56, 73, 72, 20, 86, 99};
int storage[4] = {0};
char answer = ' ';
cout << "Do you want to check a grade? (Y/N): ";
cin >> answer;
answer = toupper(answer);
while (answer = 'Y')
{
checkScore(scores, storage);
cout << "Do you want to check a grade? (Y/N): ";
cin >> answer;
answer = toupper(answer);
}
system("pause");
return 0;
} //end of main function
//*****Function Defenitions*****
void checkGrade(int scores[], int storage[])
{
int temp = 0;
int earnedScore = 0;
cout << "Enter a grade you want to check: ";
cin >> earnedScore;
for (int sub = 0; sub <= 20; sub +=1)
{
if (scores[sub] = earnedScore)
{
storage[temp] += 1;
}
}
}
问题是函数定义的命名与函数声明的命名不同:
void checkScore( int scores[], int storage[]);
void checkGrade(int scores[], int storage[])
你需要选择其中之一。编译器得到对checkScore
的调用,并看到它没有定义。将定义更改为checkScore
将解决此问题。
main()函数下面的函数checkGrade()
可能应该称为void checkScore( int scores[], int storage[])
这意味着您声明了要命名为checkScore
的函数,但是您定义了要命名为checkGrade
的函数。然后,当main()
尝试调用checkScore
时,编译器说"OK,上面已经声明了。"即使我找不到,我也会允许的。它可能在不同的库或源文件中。"然后链接器就有责任找到它。由于链接器找到了checkGrade
,但没有找到checkScore
,因此链接器抛出错误,称未定义引用(main()
引用了checkScore
而不是checkGrade
)。
看来你已经声明了你的函数
void checkScore( int scores[], int storage[]);
,但实际上没有定义它(给它一个函数体)。像
这样定义函数void checkScore( int scores[], int storage[]){
}
相关文章:
- DLL+导出类+模板成员func=未解析的外部符号.任何修复的机会
- 如何修复架构x86_64的未定义符号,Boost Asio 1.58
- 如何修复"未解析的外部符号"公共:void__thiscall canoid::getinput(void)"(?Getinput@Canoid@@QAEXXZ) 在函数 _main C++ 中引用
- 即使使用lib文件也无法修复未解析的外部符号_AES_encrypt
- Unicode Chars显示为十进制数字而不是符号,我该如何修复
- 如何修复此 OpenCV 错误:断言失败((无符号)i < (无符号)cn) 在 cv::Vec<unsigned char,3>:::运算符 (), 文件
- 使用 Boost.Python 修复未解析的外部符号
- 如何修复 c++ 提升 http 示例中的"找不到架构x86_64符号"错误
- 修复向后数组.size() 无符号整数
- 企业架构师错误:意外符号修复
- 我如何在我的C DLL中修复未解决的外部符号错误
- 什么是未定义的引用/未解决的外部符号错误以及如何修复它
- 使用 LLVM 的 libc++ 时,__1 符号从何而来?
- lnk2019未修复的外部符号
- 如何在无符号 N 位交互器中修复二进制点的位置
- 如何修复LNK2019未解析的外部符号
- 未解析的外部符号,尝试修复时遇到问题
- 错误LNK1152:无法解析一个或多个未修饰的符号.如何修复
- 无法解析的外部符号-如何修复
- 修复LNK2019:无法解决的外部符号与freeglut