2016-06-23 18 views
1

私が間違ったことを理解できません。私はいくつかの例とcppreferenceを行って、何も出てこなかった。C++のマルチスレッドで "no matching function call"エラーが発生しました

forループを使用して多数のスレッドを実行しようとすると、関数 "evaluate"が呼び出されます。私はシリーズでプログラムを実行すると何のコンパイルの問題はありません、しかし、マルチスレッドを追加すると、次が得られます。

GraphEvaluate.cpp:35:70: error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, const std::vector<std::vector<double> >&, const std::vector<InVec>&, InVec&, Graph&)’ 
    t[iii] = std::thread(evaluate, controlSpace, stateSpace, box, graph); 

私は「評価する」方法を理解していない「未解決のオーバーロードされた関数型」です。

... 
std::thread t[g_threads-1]; 


int counter(0); 


for(int iii = 0 ; iii < (g_threads - 1) ; ++iii) 
{ 
    InVec box(stateSpace.at(counter)); 
    t[iii] = std::thread(evaluate, controlSpace, stateSpace, box, graph); 
    counter += 1; 
} 


for(int iii = 0 ; iii < (g_threads - 1) ; ++iii) 
{ 
    t[iii].join(); 
} 
... 

し、評価機能:

void evaluate(const std::vector<std::vector<double>> &controlSpace, 
    const std::vector<InVec> &stateSpace, InVec box, Graph &graph) 
{ 
    std::vector<InVec> boxList; // create empty vector of InVec objects 
    SPnode ASP(box);    // create subpaving node with box 
    mince(ASP, g_epsilon);  // mince box 
    treeToList(ASP, boxList); // convert tree to list for efficient mapping 


    // map each box in boxList with mapping defined in GraphMapping.cpp for each 
    // controller value 
    for (auto control : controlSpace) 
    { 
     ImList imageList; 

     for (auto box : boxList) 
     { 
      imageList.addBox(mapping(box, control)); 
     } 

     InVec intersectionBox(inclusionMap(imageList)); 
     std::vector<InVec> intersectingBoxes; // list of boxes in state space 
     // that intersect with intersectionBox 

     for (auto ssBox : stateSpace) 
     { 
      if (!(noIntersection(ssBox, intersectionBox))) 
       intersectingBoxes.push_back(ssBox); 
     } 


     std::vector<int> nodeList; // list of nodes that box (function input) 
     // points to with the given control 

     if (!(intersectingBoxes.empty())) 
     { 
      for (auto ssBox : intersectingBoxes) 
      { 
       for (auto image : imageList.getList()) 
       { 
        if (!(noIntersection(ssBox, image))) 
        { 
         nodeList.push_back(ssBox.getBoxNumber()); 
         break; 
        } 
       } 
      } 
     } 


     if (!(nodeList.empty())) 
     { 
      for (auto node : nodeList) 
      { 
       graph.setAdjList(box.getBoxNumber(), Edge(node, control)); 
      } 
     } 
    } 
} 

すべてのヘルプは高く評価されてここで

コードがあります。

+2

'std :: ref'を使用する必要があります。つまり、' std :: ref'を使用する必要があります。 'std :: ref(controlSpace)、std :: ref(stateSpace) – chema989

答えて

2

std::threadのコンストラクタは、引数型を推定し、値で格納します。

C++テンプレート関数引数型減算メカニズムは、型Tを引数T&から導き出します。したがって、std::threadへのすべての引数は値渡しされます。

@MaximEgorushkinあなたがstd::ref()を使用して引数を包む、その引数はstd::threadから参照されている関数を呼び出す必要がある場合。たとえば:this postを参照してください

void evaluate(std::vector<std::vector<double>> controlSpace, 
    std::vector<InVec> stateSpace, InVec box, Graph graph); 

:一方

std::thread(evaluate, std::ref(controlSpace), std::ref(stateSpace), box, std::ref(graph)); 

、あなたは次のようにevaluate関数の宣言を変更する必要があります。

+0

奇妙なことに、これは動作していないようですが、上記のエラーメッセージが表示されます。ラップされたパラメータの前にstd :: reference_wrapperがあります。 – duncster94

+1

はメンバークラスを評価していますか? – chema989

+0

'evaluate'は私が別のコードで使った関数ですが、私のオブジェクトのいくつかには友人として含まれていました。私はまだ、 'std :: thread'が私の他の関数が何もしていないときに、この友人宣言を見つけるのは奇妙だと感じています。何か案が? – duncster94

関連する問題