2016-03-19 14 views
1

私はユーザ定義のクラスのベクトルを持っており、このベクトルをソートしたいと思います。分類に基づいて3つの属性が発生します。私はラムダ関数を使用してベクトルをソートする必要がある属性を取得しています。しかし、私はコンパイラのエラーを取得しています。私は以下のコードを貼り付けています:ラムダ関数を使ってstlコンテナをソートする

mapNode * PhotonMap::createTree(int start, int end) 
{ 
    mapNode *n = new mapNode(); 

    if (end - start == 0) 
    { 
     n->node.sPosition.setVector(pMap[end].sPosition); 
     n->node.pPower.setVector(pMap[end].pPower); 
     n->sAxis = -1; 
     n->left = NULL; 
     n->right = NULL; 
     return n; 
    } 

    BBox box; 

    if (!(end - start + 1 == pMap.size())) 
     box.setBBox(computeBox(start, end)); 

    int splitAxis = decodeSplitAxis(box.getMaxSpreadAxis()); 
    n->sAxis = splitAxis; 

    std::sort(pMap[start], pMap[end], [splitAxis](Photon &first, Photon &second) ->bool { return (first.sPosition.getValue(splitAxis) > second.sPosition.getValue(splitAxis)); }); 

    int mIndex = floor((start + end)/2); 

    n->node.sPosition.setVector(pMap[mIndex].sPosition); 
    n->node.pPower.setVector(pMap[mIndex].pPower); 

    if (mIndex == start) 
    { 
     //this means end - start = 1. There will be no left node! 
     n->left = NULL; 
     n->right = createTree(mIndex + 1, end); 
     return n; 
    } 
    else { 
     n->left = createTree(start, mIndex); 
     n->right = createTree(mIndex + 1, end); 
     return n; 
    } 

} 

を私は取得していますエラーは次のとおりです。

エラーC2784:「不明な型のstd ::演算子を - (STD :: move_iterator < _RanIt> & ( - 不明な型のstd ::演算子:フォトン '

エラーC2784 ' '' からのstd :: move_iterator < _RanIt> &:、constのはstd :: move_iterator < _RanIt2> &)' のテンプレート引数を推定できませんでした'短所トンのstd :: reverse_iterator < _RanIt> &、constのはstd :: reverse_iterator < _RanIt2> &) 'のテンプレート引数を推定できなかった 'のconstのstd :: reverse_iterator < _RanIt> &フォトン '

エラーC2676' から':バイナリ「 - 」:「フォトン」は事前に定義されたオペレータに許容されるこの演算子またはタイプへの変換を定義していない

エラーC2672:「_Sort」:「ボイドSTD:なしマッチングオーバーロード機能が

エラーC2780を発見:: _ソート(_RanIt、_RanIt、_Diff、_Pr) ':4つの引数を必要とする - 3が提供される

Photonは、structである。 )(std::sort

int length; 
void allocateMemory(void); 
float vector[3]; 

答えて

1

最初の2つのパラメータの反復子ではなく、容器の内容物への言及すべきである:

typedef struct Photon { 

    Vector sPosition; 
    Vector iDirection; 
    Vector pPower; 
    Vector norm; 

} Photon; 

Vectorは、そのプライベートメンバーでclassある:その宣言です。あなたがMinimum, Complete, and Verifieable exampleを提供しなかったので、またコンパイルを防ぐため、あなたのコードで他の問題があるかもしれません

std::sort(&pMap[start], &pMap[end], /* your lambda goes here */); 

が、これはそれらの少なくとも最初の1です:ポインタはそう、あまりにも動作します。

関連する問題