【发布时间】:2014-04-05 21:47:39
【问题描述】:
我实际上是编程新手,我对这个错误一无所知。我知道这类问题之前已经回答过,但我找不到我的问题的答案。
错误是:" 1>a4main.obj : error LNK2019: unresolved external symbol "bool __cdecl operator==(class EAN const &,class EAN const *)" (??8@YA_NABVEAN@@PBV0 @@Z) 在函数 _main 中引用 "
1>C:\Users\LUV\documents\visual studio 2013\Projects\a4\Debug\a4.exe : 致命错误 LNK1120: 1 unresolved externals
**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];
}
}
包含'== operator'定义的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;
}
【问题讨论】: