我有以下的功能,即在給定的範圍內產生一個整數隨機洗牌和函數指針
18 int choosecard(){
19 boost::uniform_int<> dist(0,51);
20 boost::variate_generator< boost::mt19937&, boost::uniform_int<> > cardchoice(gen, dist);
21 return cardchoice();
22 }
我想用它作爲參數傳遞到std :: random_shuffle,這樣我可以洗牌矢量52個整數。
64 int (*pchoosecard)(void) = choosecard;
65
66 std::random_shuffle(cards.begin(), cards.end(), pchoosecard);
但是我得到這個錯誤,我不明白:
$ make
g++ -I /usr/local/boost_1_45_0/ -c main.cpp
In file included from /usr/include/c++/4.4/algorithm:62,
from /usr/local/boost_1_45_0/boost/any.hpp:13,
from /usr/local/boost_1_45_0/boost/program_options/value_semantic.hpp:12,
from /usr/local/boost_1_45_0/boost/program_options/options_description.hpp:13,
from /usr/local/boost_1_45_0/boost/program_options.hpp:15,
from main.cpp:1:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::random_shuffle(_RAIter, _RAIter, _Generator&) [with _RAIter = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, _Generator = int (*)()]’:
main.cpp:66: instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:4998: error: too many arguments to function
make: *** [main.o] Error 1
一切編譯罰款當我註釋掉調用的std :: random_shuffle行。
有人能夠解釋這個問題嗎?
謝謝,但我還是很困惑。我沒有uniform_dist構造函數。你的意思是boost :: uniform_int <> dist(0,51)的行嗎?我已經選擇了一個ptrdiff_t,我。然後將上述行更改爲boost :: uniform_int <> dist(0,i-1); 但是我只是越來越神祕的錯誤 – oadams 2010-12-04 08:04:07