错误 LNK2019:函数_main中引用未解析的外部符号"..."
error LNK2019: unresolved external symbol "..." referenced in function _main
我实际上是编程新手,我对这个错误一无所知。我知道这种类型的问题以前已经回答过,但我找不到我问题的答案。
错误是:"1>a4main.obj:错误LNK2019:未解析的外部符号"bool __cdecl运算符==(类 EAN 常量 &,类 EAN 常量 *)"(??8@YA_NABVEAN@@PBV0@@Z) 在函数 _main 中引用 "
1>C:\用户\LUV\documents\Visual Studio 2013\Projects\a4\Debug\a4.exe:致命错误LNK1120:1 个未解析的外部
**main file (a4main.cpp)**
这只是主程序的一部分,我认为问题就在这里。如果需要,我稍后会发布整个主函数。
#include <iostream>
//#include "GS1Prefix.h"
#include "Order.h"
#define MAXORDERS 100
char menu(std::istream& is);
bool style(std::istream& is, char&);
int main() {
char choice;
int noOrders = 0;
iOrder* order[MAXORDERS];
Prefix prefix("prefixRanges.txt");
std::cout << "Bookstore Order Processorn"
<< "=========================n";
// process user input
do {
choice = menu(std::cin);
std::cout << std::endl;
switch (choice) {
case 'P':
{
EAN ean;
if (ean.read(std::cin, prefix)) {
int index = -1, created = false;
for (int i = 0; i < noOrders && index == -1; i++)
if (ean == order[i]->getEAN())
index = i;
if (index == -1)
if (noOrders < MAXORDERS) {
index = noOrders;
order[noOrders++] = new Order(ean);
created = true;
}
else
std::cerr << "No space for more orders!" << std::endl;
if (!order[index]->add(std::cin) && created)
delete order[--noOrders];
}
}
EAN.cpp包含'==运算符'定义的文件
)
bool operator==(const EAN& left, const EAN& right)
{
int flag = 0;
if (!strcmp(left.prefixele,right.prefixele))
{
if (!strcmp(left.area,right.area))
{
if (!strcmp(left.publisher,right.publisher))
{
if (!strcmp(left.title,right.title))
{
if (left.checkdigit == right.checkdigit)
{
flag = 1;
}
}
}
}
}
if (flag == 1)
return true;
else
return false;
}
订单.h 文件
#include "EAN.h"
class iOrder{
public:
virtual bool add(std::istream&) = 0;
virtual void display(std::ostream& os) const = 0;
virtual bool add(int n) = 0;
virtual EAN* getEAN() = 0;
virtual bool receive(std::istream&) = 0;
virtual int outstanding() const = 0;
};
class Order: public iOrder
{
int ordered;
int delivered;
EAN ean_o;
bool empty;
public:
Order();
Order(const EAN& );
EAN* getEAN();
int outstanding() const;
bool add(std::istream& is);
bool add(int n);
bool receive(std::istream& is);
void display(std::ostream& os) const;
//virtual ~Order();
};
std::ostream& operator<< (std::ostream& os, const iOrder& order);
class SpecialOrder :public Order
{
char* instructions;
public:
SpecialOrder();
SpecialOrder(const EAN& isbn, const char* instr);
SpecialOrder(const SpecialOrder& source);
SpecialOrder& operator=(const SpecialOrder& source);
bool add(std::istream& is);
void display(std::ostream& os) const;
~SpecialOrder();
};
std::ostream& operator<< (std::ostream& os, const SpecialOrder& order);
EAN * getEAN() 函数
EAN* Order::getEAN()
{
EAN p = (*this).ean_o;
EAN* pp = &p;
return pp;
}
==
运算符需要通过引用传递两个EAN
参数。但是,用作第二个参数的 getEAN
方法传递指向 EAN
的指针,而不是引用。修改 ==
运算符以接受指针作为第二个参数,或者更改代码以通过引用传递两个EAN
。
函数 GetEAN 返回一个指针,因此该行
if (ean == order[i]->getEAN())
实际上正在尝试将 EAN 对象与内存地址进行比较
将行更改为
if (ean == *( order[i]->getEAN() ) )
应该在通过对象的值初始化引用时解决问题
相关文章:
- 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