预期的类型说明符

use*_*677 2 c++ boost c++11

当我使用boost/random/uniform_int_distribution.hpp和执行时,我收到此错误:

boost::random::uniform_int_distribution<> dist(0, 5);
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

$ g++ game.cpp -std=c++11 -Wall -Ipath/to/boost -o game && ./game

game.cpp:11:20: error: expected type-specifier
game.cpp:11:20: error: expected '>'

为什么我收到此错误?

注意:我使用时没有收到此错误std::uniform_int_distribution<>.

这是导致问题的代码:

#include <boost/random/uniform_int_distribution.hpp>

template<
    class Engine = boost::default_random_engine
>
class game
{
    boost::random::uniform_int_distribution<int> dist{0, 5};
};

int main()
{
}
Run Code Online (Sandbox Code Playgroud)

Pra*_*ian 5

Boost.Random没有定义default_random_engine类型.直接使用Mersenne twister引擎(或其定义的其他发生器之一)

#include <boost/random/uniform_int_distribution.hpp>
#include <boost/random/mersenne_twister.hpp>

template<
    class Engine = boost::mt19937
>
class game
{
    boost::random::uniform_int_distribution<> dist{0, 5};
};
Run Code Online (Sandbox Code Playgroud)

此外,由于这个问题被标记C++ 11,我会提的是,标准库不同时定义std::default_random_enginestd::uniform_int_distribution<random>报头.