簡體   English   中英

錯誤LNK2019:函數_main中引用的未解析的外部符號“...”

[英]error LNK2019: unresolved external symbol “…” referenced in function _main

我實際上是編程的新手,我不知道這個錯誤。 我知道此類問題之前已得到解答,但我無法找到問題的答案。

1> C:\\ Users \\ 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 Processor\n"
        << "=========================\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;

}

Order.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() ) )

在通過對象的值初始化引用時應該解決問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM