2016-04-21 29 views
-1

構造体の値として別のマップ/ベクトルの組み合わせを持つマップをロードしようとしました。以下は、私は私ができる限り簡素化しようとした私のコードです:C++ <map、<map, vector>>のデータとして構造体を使用

//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    
      } 
     } 

だから私はすべての値(ListofValues)のリストが含まれて渡されたオブジェクトを持つことになります。私はそのリストを繰り返し、getterメソッドを使用して、これらの値を構造体に格納します(getEはLongを返し、変換が必要です)。

error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const Order' (or there is no acceptable conversion) 
+2

[mcve]を投稿してください。あなたはコンパイラのエラーがあります。もし私があなたのコードをそのまま使っていたら、私はそれらのトンを持っています。 – PaulMcKenzie

+1

あなたのクラスOrderの演算子<()が必要だと思います。 –

+0

彼は、彼が渡した変数のTYPEで.begin()と.end()を呼び出していると、彼が主張しているエラーをどのようにしているのかよくわかりません。本当にMCVEが必要です – xaxxon

答えて

4

あなたはこの質問を参照してください、マップのキーとして使用するためにあなたの構造体のためのオペレータ<を提供する必要があります:私は取得していますエラーがある

を欠けているステップがあります:Struct as a key in a std::map

+0

これで解決しました。ありがとうございました! – Saif

2

ListOfValuesは、LoadMapに渡されるパラメータのTYPEであり、objectは実際の変数です。

forループでは、object.begin()object.end()と言う必要があります。

私は、あなたが得ていると言うよりも非常に異なるコンパイルエラーが発生しています。正しいコードを投稿しましたか?

ここに私が見るものがあります:https://godbolt.org/g/xl4zWw