Threads passing an array as an argument

In my main function I am trying to make a thread and pass down a string a array to it by doing this
int main()
{
thread DoNotWork(Print,Pages);
}
my function is this
void Print(string Pages [])

The error message is this
error: no matching function for call to ‘std::thread::thread(void (&)(std::string*), std::string [BufferSize])’
thread DoNotWork(Print,Pages);

Any help would be great!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
#include <thread>

void print( const std::string pages[], std::size_t sz )
{
    std::cout << "print( pages, sz ): pointer == " << pages << ", sz == " << sz << '\n' ;
    if(pages) for( std::size_t i = 0 ; i < sz ; ++i ) std::cout << "    page: " << pages[i] << '\n' ;
}

int main()
{
    const std::size_t sz = 5 ;
    std::string pages[sz] { "zero", "one", "two", "three", "four" } ;

    std::thread printer( print, pages, sz ) ; // array to pointer decay

    printer.join() ;
    std::cout << "done\n" ;
}

http://coliru.stacked-crooked.com/a/068a1e0904b1a6a2
http://rextester.com/ALN94722
Thank your code works can you help me find why I get this error I listed it below.

void downloader(string Pages[],int BufferSize,int WhichFile)
{
}

int main()
{
int BufferSize = 5;
string Pages[BufferSize];
thread down(downloader,Pages,BufferSize,5);
}

When I am trying to make a thread like this it gives me an error and I do not know why
this is the error message

error: no matching function for call to ‘std::thread::thread(void (&)(std::string*, int, int), std::string [BufferSize], int&, int)’
thread down(downloader,Pages,BufferSize,5);

This is not valid C++ because an array cannot have a non-constant bound
1
2
int BufferSize = 5;
string Pages[BufferSize];

If you're using gcc (which infamously permits this by default), always compile with -pedantic-errors to avoid such gotchas.
The var BufferSize will be 5 for the whole program. I am passing the size of the array with the command line. Do you know why I get this error when using threads???
Thank you guys
I fixed my mistake.
This was my first time posting and this was very helpful :D
Topic archived. No new replies allowed.