I am writing a program that holds a list<T> where T is either int or double. I want to make a function, using components from the header <random>, that generates numbers of type T. I can't find a distribution that takes T as template argument.
The function is then going to be used in a call to the generate function:
generate(myList.begin(), myList.end(), RandomGenerator()) How do I go about doing this?
I have tried to create a class called RandomGenerator and overload the operator() for it. When i try to pass an argument to the overloaded operator() i get an error.
Function call, Random(b) is a function object with int argument b:
generate(rList.begin(), rList.end(), Random(b)); Code for overloading (), where n is sort of a "dummy"-variable for just telling what type it is:
int operator()(int n) { std::uniform_int_distribution<int> dist(1000, 2000); return dist(gen); } Error message:
Error 2 error C2440: '<function-style-cast>' : cannot convert from 'int' to 'Random' Error 3 error C2780: 'void std::generate(_FwdIt,_FwdIt,_Fn0)' : expects 3 arguments - 2 provided
std::conditionaland the type-class tests such asstd::is_floating_pointandstd::is_integraluseful in this endeavor.generatewith three arguments - but the compiler says you only passed two. This strongly suggests the code you have shown is not the code you are actually compiling. Show the exact line that the error message refers to.