1

пытаясь создать функцию которая бы выдавала случайное простое число, я получаю следующие ошибки при компиляции:

Severity Code Description Project File Line Suppression State Error C2065 '_Ty1': undeclared identifier Project4 c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\xutility 3931
Warning C4244 'argument': conversion from 'time_t' to 'unsigned int', possible loss of data Project4 c:\users\andrii\documents\visual studio 2017\projects\project4\project4\source.cpp 8 Error C2825 '_Urng': must be a class or namespace when followed by '::' Project4 c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\xutility 3929
Error C2510 '_Urng': left of '::' must be a class/struct/union Project4 c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\xutility 3929
Error C2061 syntax error: identifier 'result_type' Project4 c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\xutility 3929
Error C2238 unexpected token(s) preceding ';' Project4 c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\xutility 3929
Error C2065 '_Ty1': undeclared identifier Project4 c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\xutility 3931
Error C2923 'std::conditional_t': '_Ty1' is not a valid template type argument for parameter '_Ty2' Project4 c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\xutility 3931

#include<iostream>
#include <cstddef>
#include <random>
#include <ctime>

int GetRandomNumber(std::size_t f = 300, std::size_t d = 1000)
{
    static std::default_random_engine dre(std::time(nullptr));
    return std::uniform_int_distribution<>()(f, d);
}

int main()
{
    std::cout << GetRandomNumber() << std::endl;
    return 0;
    system("pause");

}

Буду очень благодарен всем, кто объяснит мне мои ошибки.

1 ответ 1

0

Аргументами конструктора для distribution являются числа, задающие диапазон (которые в данном случае должны быть int а не size_t), а аргументом оператора () - генератор (который у вас не задействуется никак). Должно быть так:

return std::uniform_int_distribution<>{f, d}(dre);
1
  • Большое спасибо за помощь 16 мая 2018 в 20:44

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.