为什么我的随机数类会导致链接器错误?

时间:2015-01-03 23:50:40

标签: c++ random

错误讯息:

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。 我希望你能帮助我。提前谢谢!

0 个答案:

没有答案