错误 LNK2019:函数_main中引用未解析的外部符号"..."

error LNK2019: unresolved external symbol "..." referenced in function _main

本文关键字:外部 符号 引用 LNK2019 函数 main 错误      更新时间:2023-10-16

我实际上是编程新手,我对这个错误一无所知。我知道这种类型的问题以前已经回答过,但我找不到我问题的答案。

错误是:"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() ) )

应该在通过对象的值初始化引用时解决问题