未解析的外部符号
Unresolved external symbol
错误1错误LNK2019:未解析的外部符号"bool __cdeclprefix(unsigned int,unsigned整型)"(?prefix@@YA_NII@Z)中引用函数(_main)c:\Users\Work\documents\visual studio2012\项目\书籍\项目5\项目5\Source.obj项目5
错误2错误LNK1120:1未解析externals c:\users\work\documents\visualstudio2012\Projects\Book\Project5\Debug\Project5.exe 1 1 Project5
我只是。。我甚至不知道该问你们什么。我该如何解决这个问题?
这是代码:
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
void citire(vector<unsigned int> myVector,int &nrElem);
bool prefix(unsigned int nr1,unsigned int nr2);
int main(){
int nrElem={0};
vector<unsigned int> myVector;
//citire(myVector,nrElem);
cout << prefix(123,1234);
system("pause");
return 0;
}
void citire(vector<unsigned int> myVector,int &nrElem){
cout << "NumarElemente=" ;
cin >> nrElem ;
for(int i=0;i<nrElem;i++){
unsigned int nrCitit;
cout << "Elem #" << i+1 <<"=";
cin >> nrCitit;
myVector.push_back(nrCitit);
};
for(int i=0;i<nrElem;i++){
cout << myVector.at(i);
};
}
bool prefix(unsigned int &nr1,unsigned int &nr2){
unsigned int nr1copy=nr1;
unsigned int nr2copy=nr2;
int digitsNr1 = 0; while (nr1copy != 0) { nr1copy /= 10; digitsNr1++; }
int digitsNr2 = 0; while (nr2copy != 0) { nr2copy /= 10; digitsNr1++; }
if ( nr2/_Pow_int(10,digitsNr2-digitsNr1)==nr1) {return true;}
else return false;
}
bool prefix(unsigned int nr1,unsigned int nr2);
与不同
bool prefix(unsigned int& nr1,unsigned int &nr2);
在正向-正向声明中,您按值获取参数,但在定义中是按引用获取参数。在声明和定义中保持参数类型相同。
未解析的外部符号"bool __cdecl前缀(无符号int,无符号int)"
通常,当您看到此类链接器错误时,首先需要检查的是函数的声明和定义签名是否匹配。在这种情况下,显然不是。
声明:
bool prefix(unsigned int nr1,unsigned int nr2);
定义:
bool prefix(unsigned int &nr1,unsigned int &nr2){ ... }
看到区别了吗?两者应该相同。查看您的代码,您似乎应该将版本保留在声明中。
prefix()
函数有一个原型:
bool prefix(unsigned int nr1,unsigned int nr2);
其签名与下面给出的实现不同:
bool prefix(unsigned int &nr1,unsigned int &nr2) {
^^^ ^^^
....
}
注意,在原型中,nr1
和nr2
参数通过值传递;相反,在实现签名中,它们是通过引用传递的(注意&
)。
原型签名和实现签名都应该匹配。修错了
(注意:由于不能将main()
中的123
等文本作为非const
引用传递,我认为错误的是实现签名,即在实现签名中丢弃&
)。
相关文章:
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 未解析的外部符号_MsiLocateComponentW@12.
- 在C++中使用 gRPC 时未解析的外部符号
- LibPrivoxy: 未解析的外部符号 __declspec(dllimport) int __stdcall Sta
- 尝试从 XamlApplication 编译 C++/WinRT 空白应用程序时,我收到未解析的外部符号 winrt_make_*
- 我收到错误LNK2001:未解析的外部符号(C++代码)
- 可视抽象类 c++(错误 LNK 2001:未解析的外部符号)
- 如何摆脱C++中未解析的外部符号"private: static char"错误?
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 仅在少数方法(静态或共享库)中解析的外部符号
- 未解析的外部符号"__declspec(dllimport)与 Spdlog c++ 库
- 函数 _main (OPENGL C++) 中引用的未解析的外部符号 ________
- 错误LNK2019未解析的外部符号"public: __thiscall SLinkList<char>::SLinkList<char>(void)"
- 使用静态 constexpr 成员的未解析外部符号
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- Dlib LNK2001未解析的外部符号USER_ERROR__consistent_build_configurati
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 链接器错误:切换到unicode生成给出:未解析的外部符号WinMain
- 类模板上一个特定函数的未解析外部符号
- LNK2001:未解析的外部符号public:static类std::vector