错误讯息:
Error 3 error LNK2001: Non-resolved external symbol ""private: static class std::mersenne_twister_engine<unsigned int,32,624,397,31,2567483615,11,4294967295,7,2636928640,15,4022730752,18,1812433253> Randomizer::_generator
Randomizer.h
#pragma once
#include <random>
class Randomizer
{
public:
static void init();
static float getRand(const float min, const float max);
static int getRand(const int min, const int max);
private:
static std::mt19937 _generator;
};
Randomizer.cpp
#include "Randomizer.h"
#include <ctime>
void Randomizer::init()
{
_generator.seed(time(0));
}
float Randomizer::getRand(const float min, const float max)
{
std::uniform_real_distribution<float> dist(min, max);
return dist(_generator);
}
int Randomizer::getRand(const int min, const int max)
{
std::uniform_int_distribution<int> dist(min, max);
return dist(_generator);
}
如果重要,我正在使用visual studio 2013。 我希望你能帮助我。提前谢谢!