C2678因我没有明显理由被抛出

时间:2018-03-29 06:03:28

标签: list exception visual-c++ operator-keyword

我正在尝试编译这个项目只是为了看看我一直在做什么,但我还有一些实现的类将继承Widget的不同类型。当我编译时,我一直得到C2678:

  

错误C2678二进制' ==':找不到左侧的操作符   类型操作数' Widget' (或者没有可接受的转换)   Assignment10 c:\ program files(x86)\ microsoft visual   studio \ 2017 \ community \ vc \ tools \ msvc \ 14.11.25503 \ include \ xutility line3107

我无法找到抛出此错误的位置或原因。任何帮助将不胜感激。对不起,它很草率,我一直在弄乱它,试图找到问题。

#pragma once
#include <iostream>
using namespace std;

class Widget
{
public:


    int idNumber;
    //structors
    Widget()
    { 
        idNumber = 0;
    }
    Widget(int a) 
    { 
        idNumber = a;
    }
    ~Widget();

    //operations
    int getId() 
    {
        return idNumber;
    }
    //overload operators to compare idNumber
    void operator= (Widget &rhs)
    {
        idNumber = rhs.idNumber;
    }
};

----------------------------------------
#include "Widget.h"
#include <iostream>
using namespace std;

Widget::~Widget()
{
}

/*


bool Widget::operator< (Widget &rhs)
{
    bool result;
    result = idNumber < rhs.idNumber;
    return result;
}*/

---------------------------------
#pragma once
#include "Widget.h"
#include <list>
#include <iostream>
using namespace std;

class Inventory
{
public:
    Inventory();
    Inventory(int i)
    {
        Widget w(i);
    }
    ~Inventory();



    //operations
    //process order for shipment
    void order(int widgID);
    //recieve widget 
    void receive(int widgID);

    //overlaod output operator
    friend ostream& operator<<(ostream&, const Widget&);

protected: 
    list<Widget> onHand;
    list<int> onOrder;
};

-------------------------------
#include "Inventory.h"
#include "Widget.h"
#include <iostream>
#include <list>
using namespace std;


Inventory::Inventory()
{
    Widget w;
}

Inventory::~Inventory()
{
}

//recieve widget 
void Inventory::receive(int widgID)
{
    cout << " Recieved shipment of Widget type "
        << widgID << endl;

    //find the iterator of the widget location
    list<int>::iterator weNeed;
    weNeed = find(onOrder.begin(), onOrder.end(), widgID);

    //if end is returned, item not found
    if (weNeed != onOrder.end())
    {
        cout << "Ship " << Widget(widgID) << " to fill back order" << endl;
        onOrder.erase(weNeed);

    }
    else
    {
        onHand.push_front(Widget(widgID));
    }
}

//process order
void Inventory::order(int widgID)
{
    cout << " Recieved order for Widget type "
        << widgID << endl;

    //find the iterator of the widget location
    list<Widget>::iterator weHave;
    weHave = find(onHand.begin(), onHand.end(), widgID);    


    //if end is returned, item not found
    if (weHave != onHand.end())
    {
        cout << "Ship " << *weHave <<  endl;
        onHand.erase(weHave);

    }
    else
    {
        cout << "Back order widget of type "
            << widgID << endl;
        onHand.push_front(Widget(widgID));
    }
}



ostream& operator<<(ostream& os, const Widget& wid)
{
    os << wid.idNumber;
    return os;
}

0 个答案:

没有答案
相关问题