2017-01-08 6 views
-2

私はC++スレッディングの新人です。私はビジュアルスタジオのエラーを取り除く方法を知っています。次のような2つのエラーが発生します。 1)C2672: 'std :: invoke'一致するオーバーロードされた関数が見つかりません。 2)C2893は:クラスの公開機能でマルチスレッドを使用しています

#include <iostream> 
#include <string> 
#include <thread> 
using namespace std; 
struct q_node { 
    q_node *previous; 
    q_node *next; 
    string data; 

}; 
class q { 
private: 
    q_node * aa; 
    q_node * bb; 
    q_node * ans; 
    q_node *front; 
    q_node *current; 
    int element; 
    int counter1; 
    int counter2; 
public: 
    q() { 
     front = NULL; 
     current = NULL; 
     element = 0; 
     aa = NULL; 
     bb = NULL; 
    } 
    void enque(string team) { 
     q_node *t = new q_node; 
     t->previous = NULL; 
     t->next = NULL; 
     t->data = team; 
     if ((front == NULL) && (current == NULL) && (element == 0)) { 
      front = t; 
     } 
     else { 
      current->next = t; 
      t->previous = current; 
     } 
     element++; 
     current = t; 
    } 
    void insert_at_index(int n, string x) { 
     q_node * t = new q_node; 
     t->previous = NULL; 
     t->next = NULL; 
     t->data = x; 
     q_node *temp, *temp2; 
     temp = front; 
     temp2 = temp->next; 
     if (n == 1) { 
      t->next = temp; 
      temp->previous = t; 
      front = t; 
     } 
     else { 
      for (int i = 0; i < element - 1; i++) { 
       if (i == (n - 2)) { 
        temp->next = t; 
        t->previous = temp; 
        t->next = temp2; 
        temp2->previous = t; 
        temp2 = front; 
       } 
       temp = temp->next; 
       temp2 = temp2->next; 
      } 

     } 
     element++; 
    } 

    void deque() { 
     q_node *temp = front; 
     front = front->next; 
     front->previous = NULL; 
     temp->next = NULL; 
     element--; 
     delete temp; 
    } 
    void display() { 
     q_node *t = front; 
     for (int i = 0; i < element; i++) { 
      cout << " " << t->data << " "; 
      t = t->next; 
     } 
    } 
    inline void checking() {         //decide values for both integer e.g for 9 (4,5) 
     if ((element % 2) == 0) { 
      counter1 = ((element/2) - 1); 
      counter2 = ((element/2) + 1); 
     } 
     else { 
      counter1 = ((element/2)); 
      counter2 = ((element/2) + 1); 
     } 
    } 
    void search_first(string x) {    //transverse from start 
     q_node *t = front; 
     int i = 0; 
     for (; i < counter1; i++) { 
      if (t->data == x) { 
       bb= t; 
       break; 
      } 
      t = t->next; 
     } 
     if (i == counter1) { 
      bb= NULL; 
     } 
    } 
    void search_last(string x) {     //transverse from end 
     q_node *t = current; 
     int i = 0; 
     for (; i < counter2; i++) { 
      if (t->data == x) { 
       aa= t; 
      } 
      t = t->previous; 
     } 
     if (i==counter2) { 
      aa = NULL; 
     } 
    } 
    void get_search(string aaa) { 

     thread t(&q::search_first, aaa); 
     thread tt(&q::search_last, aaa); 
     t.join(); 
     tt.join(); 
     if (aa != NULL&&bb != NULL) { 
      if (aa != NULL) { 
       ans = aa; 
      } 
      else { 
       ans = bb; 
      } 
     } 
     else { 
      ans = NULL; 
     } 
    } 
    void smart_insertion(string a) { 
     get_search(a); 
     if (ans!=NULL) { 
      q_node * t = new q_node; 
      t->data = a; 
      t->previous = ans; 
      t->next = (ans->next); 
      ans->next = t; 
      (ans->next)->previous = t; 
     } 
     else { 
      enque(a); 
     } 
    } 
}; 

私がしようとしています:関数型を専門に失敗しました

これは私のコードされた '未知の型のstd ::(_Callable & &、_Typers & &を...)を呼び出します' 2つのスレッドを使用してリンクリストを両側から読み取り、全体の速度が向上するようにします。ここのキューは、二重リンクリストを使用して実装されています。誰かがエラーで私を助けてくださいできますか?

答えて

0

非静的メンバー関数でスレッドを呼び出すには、スレッドを実行するオブジェクトへのポインタを渡す必要があります。 thisはそれを次のとおりです。

thread t(&q::search_first, this, aaa); 
    thread tt(&q::search_last, this, aaa); 

は確かに私はあなたのコードは、あなたがやっていることを達成することを約束いけないが、これは、このエラーを過ぎてあなたを取得し、コードをコンパイルします。

+0

ありがとうございました。それは助けになった – Asad

関連する問題