-1

I am having a problem trying to load a map that has another map/vector combination as the value with structs. Below is my code which I have tried to simplify as much as I could:

    //These are the structs
    struct Order 
    {
        std::string A;
        std::string B;
    };

    struct Card
    {
        std::string C;
        std::string D;
    };

    struct Item  
    {
        std::string E;
        std::string F;
    };

    //this is the method that will read and load the map
    void LoadMap(ListofValues object)
    {
    std::map<Order, std::map<Item, std::vector<Card>>> records; //THIS is the data structure I'm trying to store into

    //ListofValues is a list passed that holds all these values that will need to be put into my map
    for(std::vector<ListofValues>::iterator vIter= object.begin(); vIter != object.end(); ++vIter)
            {           
                std::string sReceiptRecord = (*vIter).getReceipt(m_StdOrderConfirmVer);

                Order order = {(*vIter).getA,(*vIter).getB}; 
                Item item = {(*vIter).getC,(*vIter).getD}; 
                Card card = {wws::String((*vIter).getE), (*vIter).getF}; 

                records[order][item].push_back(card); //load into my map            
            }
      }

So I will have an object passed that contains a list of all the values (ListofValues). I will iterate through that list and with the getter methods, I will store those values into the structs (getE returns a Long which is why the conversion was necessary). Is there a step I'm missing

An error I'm getting is:

error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const Order' (or there is no acceptable conversion)
Saif
  • 21
  • 3
  • 2
    Please post an [mcve]. You have a compiler error, and if I took your code as-is, I would have a ton of them. – PaulMcKenzie Apr 21 '16 at 20:20
  • 1
    I think you need an operator <() for your class Order. – 2785528 Apr 21 '16 at 20:20
  • Not sure how he's getting the error he claims - he's calling .begin() and .end() on the TYPE of the variable he passed in. Really need the MCVE – xaxxon Apr 21 '16 at 20:26
  • @OP See [this](http://ideone.com/po2m8O)? Same error, and the example is complete. All C++ errors can be recreated with a simple example, and you should have broken your code down to discover what is causing the problem, instead of having vectors, `String`, iterators, etc... – PaulMcKenzie Apr 21 '16 at 20:27
  • Sorry all, I confused myself while trying to translate the specific code into a more concise, general code. There's about a hundred lines I had to take out just to get the parts that are relevant. – Saif Apr 21 '16 at 20:35

2 Answers2

4

You need to provide an operator < for your struct to be used as a key for the map, see this question: Struct as a key in a std::map

Community
  • 1
  • 1
rickyviking
  • 846
  • 6
  • 17
2

ListOfValues is the TYPE of the parameter passed to LoadMap, object is the actual variable.

In your for loop, you need to say object.begin() and object.end().

I'm getting very different compiler errors than what you say you're getting. Did you post the right code?

Here's what I see: https://godbolt.org/g/xl4zWw

xaxxon
  • 19,189
  • 5
  • 50
  • 80