1

我正在研究 C++ 中的随机数生成,我已经从以下站点实现了它:

https://www.quantstart.com/articles/Random-Number-Generation-via-Linear-Congruential-Generators-in-C/

运行此程序时,我收到以下错误:

main.cpp:12:31: error: cannot declare variable ‘lcg’ to be of abstract type ‘LinearCongruentialGenerator’
   12 |   LinearCongruentialGenerator lcg(num_draws, init_seed);
      |                               ^~~
In file included from main.cpp:2:
lin_con_gen.h:6:7: note:   because the following virtual functions are pure within ‘LinearCongruentialGenerator’:
    6 | class LinearCongruentialGenerator : public RandomNumberGenerator
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from lin_con_gen.h:4,
                 from main.cpp:2:
random.h:30:18: note:   ‘virtual void RandomNumberGenerator::get_uniform_draws(std::vector&)’
   30 |     virtual void get_uniform_draws(std::vector<double>& draws) = 0;
      |                  ^~~~~~~~~~~~~~~~~
lin_con_gen.cpp:51:6: error: no declaration matches ‘void LinearCongruentialGenerator::get_unifrom_draws(std::vector&)’
   51 | void LinearCongruentialGenerator::get_unifrom_draws(std::vector<double>&draws)
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
lin_con_gen.cpp:51:6: note: no functions named ‘void LinearCongruentialGenerator::get_unifrom_draws(std::vector&)’
In file included from lin_con_gen.cpp:4:
lin_con_gen.h:6:7: note: ‘class LinearCongruentialGenerator’ defined here
    6 | class LinearCongruentialGenerator : public RandomNumberGenerator
      |

请帮助我正确运行它。

4

0 回答 0