On 30 Nov., 17:16, Leigh Johnston wrote:
> On 30/11/2011 15:37, Juha Nieminen wrote:
> > * *Any suggestions how to make this compile?
>
> > //-----------------------------------------------------------------------
> > #include<algorithm>
> > #include<cstdlib>
>
> > // The actual rng replaced with std::rand() for simplicity
> > unsigned randValue() { return std::rand(); }
> > unsigned randValue(unsigned modulo) { return std::rand() % modulo; }
>
> > int main()
> > {
> > * * *int table[10];
> > * * *std::random_shuffle(table, table+10, randValue);
> > }
> > //-----------------------------------------------------------------------
>
> > * *(Other than removing the first randValue() function, of course.)
>
> * * * * unsigned(*pf)(unsigned) = &randValue;
> * * * * std::random_shuffle(table, table+10, pf);
Alternatives:
(1) static_cast:
random_shuffle(...,static_cast<unsigned(*)(unsigne d)>(randValue));
(2) A C++2011 lambda expression:
random_shuffle(...,[](unsigned i){return randValue(i);});
Cheers!
SG
|