开发者

std::random_shuffle, compiler error: no matching function for call

I cannot compile following code by g++ 4.3.2:

#include <stdlib.h>
#include <algorithm>

struct Generator {
  ptrdiff_t operator() (ptrdiff_t max) {
    return rand() % max;
  }
};

Generator g开发者_开发百科enerator;
std::vector<size_t> indices;
// fill vector
std::random_shuffle(indices.begin(), indices.end(), generator); // error here!

Why my compiler throws following error in last line?

error: no matching function for call to ‘random_shuffle(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, Generator&)’

Thanks in advance!


Actually in my code Generator structure is declared within a function. I don't know wjy, but g++ 4.3.2 does not accept this. After I moved structure declaration out of function, compilation successes. I believe this is a bug in compiler. Moreover original code was successfully compiled by earlier version of g++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜