lundi 27 juillet 2015

c++ 11: why I recive the error : no matching function for call std::thread::thread?

I wrote this function for implement multithrading, I recive this error and I don't understand why and how to fix it. I'm testing c++11 threads with this code, but when creating the thread, I'm having the error no matching function for call to 'std::thread::thread()'. I think that the problem is in how I call the function in thread, but I can't see what is wrong, it looks good to me.

    void Data::Set( const BeBoard* pBoard, const std::vector<uint32_t>& pData, uint32_t pNevents, bool swapBytes )
    {
        std::vector<uint32_t> cVectorCopy;
        cVectorCopy = deepCopy( pData );

        std::thread cThreads[2];
        for ( int i = 0; i < 2; ++i )
        {
            cThreads[0] = std::thread( Data::writeFile, cVectorCopy, "outputfile" );

            cThreads[1] = std::thread( Data::SetSpecialized, pBoard, pData, pNevents, swapBytes );
            for ( int i = 0; i < 2; ++i )
                cThreads[i].join();
        }

the functions called

    void Data::writeFile( std::vector<uint32_t> fData , std::string fFileName )
    {

        //check if the file already exists
        if ( boost::filesystem::exists( fFileName + ".bin" ) )
            remove( ( fFileName + ".bin" ).c_str() );




        std::ofstream ofile( ( fFileName + ".bin" ).c_str(), std::ios::binary );

        //write the bin file
        for ( auto& cElements : fData )
            ofile.write( ( char* ) &cElements, sizeof( uint8_t ) );






    }


    void Data::SetSpecialized( const BeBoard* pBoard, const std::vector<uint32_t>& pData, uint32_t pNevents, bool swapBytes )
    {

// just do a swap of the bytes

    }

And now the output:

<pre><code>

Data.cc: In member function ‘void Ph2_HwInterface::Data::Set(const Ph2_HwDescription::BeBoard*, const std::vector<unsigned int>&, uint32_t, bool)’:
Data.cc:38:74: error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, std::vector<unsigned int>&, const char [11])’
    cThreads[0] = std::thread( Data::writeFile, cVectorCopy, "outputfile" );

Data.cc:38:74: note: candidates are:
In file included from ../Utils/Data.h:22:0,
                 from Data.cc:12:
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/thread:133:7: note: std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (Ph2_HwInterface::Data::*)(std::vector<unsigned int>, std::basic_string<char>); _Args = {std::vector<unsigned int, std::allocator<unsigned int> >&, const char (&)[11]}]
       thread(_Callable&& __f, _Args&&... __args)
       ^
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/thread:133:7: note:   no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘void (Ph2_HwInterface::Data::*&&)(std::vector<unsigned int>, std::basic_string<char>)’
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/thread:128:5: note: std::thread::thread(std::thread&&)
     thread(thread&& __t) noexcept
     ^
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/thread:128:5: note:   candidate expects 1 argument, 3 provided
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/thread:122:5: note: std::thread::thread()
     thread() noexcept = default;
     ^
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/thread:122:5: note:   candidate expects 0 arguments, 3 provided
Data.cc:40:88: error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, const Ph2_HwDescription::BeBoard*&, const std::vector<unsigned int>&, uint32_t&, bool&)’
    cThreads[1] = std::thread( Data::SetSpecialized, pBoard, pData, pNevents, swapBytes );


</pre></code>

Aucun commentaire:

Enregistrer un commentaire