我有Random类,但我不知道如何正确初始化其静态数据成员。
// random.h
#pragma once
#include <random>
class Random
{
private:
static std::uniform_real_distribution<float> sDistribution_;
static std::mt19937 sGenerator_;
};
Run Code Online (Sandbox Code Playgroud)
// random.cpp
#include "random.h"
std::mt19937 Random::sGenerator_(std::random_device()); // error here
std::uniform_real_distribution<float> Random::sDistribution_(0.0f, 1.0f);
Run Code Online (Sandbox Code Playgroud)
当我编译这个时,我收到一个错误:
声明与 不兼容
std::mt19937。
如何正确初始化该成员?