Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Unresolved overload type in parameter to std::random_shuffle

Reply
Thread Tools

Unresolved overload type in parameter to std::random_shuffle

 
 
Juha Nieminen
Guest
Posts: n/a
 
      11-30-2011
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.)

 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      12-02-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameter Type/Size Property Values for VARCHAR(MAX) Stored Proc Parameter jcpc ASP .Net 2 01-26-2011 11:48 AM
function overload (not operator overload) Ying-Chieh Liao Perl Misc 3 10-11-2004 11:24 AM
How use the overload of>> (or<<) of a class in the overload of << and >> of another class? Piotre Ugrumov C++ 3 01-25-2004 08:08 PM
Interesting parameter overload prob... Noah Roberts C++ 5 10-11-2003 05:08 PM
Default type-value for template parameter type Ragnar C++ 2 09-04-2003 09:05 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57