1
#include <random>

int main()
{
    using namespace std;
    mt19937_64 gen1(random_device()());//fail?
    mt19937_64 gen2((random_device()()));//success
    mt19937_64 gen3{ random_device()() };//success
    mt19937_64 gen4(random_device{}());//success
    return 0;
}

http://ideone.com/ukudui

The complier gives me these infomation below ,but I still don't understand why my code is illegal :

prog.cpp: In function 'int main()':

prog.cpp:6:33: error: 'parameter' declared as function returning a function

mt19937_64 gen(random_device()());

M.M
  • 138,810
  • 21
  • 208
  • 365
iouvxz
  • 89
  • 9
  • 27
  • 1
    Looks to me like most vexing parse makes `gen1` to be read by the compiler as a function, and then the declared parameter doesn't make sense at all (function returning a function) – krzaq Sep 30 '16 at 01:41
  • 1
    From using clang++: "warning: parentheses were disambiguated as a function declaration [-Wvexing-parse]". – Robert Prévost Sep 30 '16 at 01:45
  • Read [this](https://en.wikipedia.org/wiki/Most_vexing_parse) – DDMC Sep 30 '16 at 03:10
  • `gen1` can be parsed as: function returning `mt19937_64` , taking parameter of type: function taking no arguments returning (function taking no arguments returning `random_device`) – M.M Sep 30 '16 at 03:59

0 Answers0