0

私は次のような機能を持っています

 void test(const int * x, int d){
     for(int i=0; i<d ; i++)
         cout<< x[i] << endl;
 }

boost::threadで実行しようとすると

int n=10;
int * x1=new int[n];
boost::thread *new_thread = new boost::thread(& test,x1,n);

次のコンパイルエラーが発生します

error: no matching function for call to ‘boost::thread::thread(<unresolved overloaded function type>, int*&, uint16_t&)’
/usr/include/boost/thread/detail/thread.hpp:216: note: candidates are: boost::thread::thread(boost::detail::thread_move_t<boost::thread>)
/usr/include/boost/thread/detail/thread.hpp:155: note:                 boost::thread::thread()
/usr/include/boost/thread/detail/thread.hpp:123: note:                 boost::thread::thread(boost::detail::thread_data_ptr)
/usr/include/boost/thread/detail/thread.hpp:114: note:                 boost::thread::thread(boost::thread&)
main.cpp:397: warning: unused variable ‘new_thread’

確かに、私は後押しする初心者です。ありがとうございました。

4

1 に答える 1

3

test関数がオーバーロードされているようです:

//here
void test(const int * x, int d){
     for(int i=0; i<d ; i++)
         cout<< x[i] << endl;
 }

//somewhere
void test()
{
     std::cout <<"hahahahaha\n";
}

さて、test名前を指定すると

boost::thread *new_thread = new boost::thread(& test,x1,n);

testコンパイラは、ある関数を使用するか、別の関数を使用するかを知ることができません。

  • 使用するオーバーロードを指定する必要があります。

    boost::thread *new_thread = new boost::thread((void(*)(const int*, int)) test,x1,n);
    
  • またはtest関数の名前を変更します

于 2013-01-19T11:37:23.313 に答える