简体   繁体   English

在这个独家新闻中没有声明 roll_die

[英]roll_die was not declared at this scoop

I have my.hpp:我有我的.hpp:

#include <vector>
#include <iostream>
#include <ctime>
#include <random>

#ifndef ECHELLE
#define ECHELLE

struct Player{
    int position;
    int n_step;
    Player(): position(0), n_step(0) {};
};

class SnakesAndLadders{
    private:
        int n_players;
        int n_board;
        std::vector<Player> players;
        std::vector<int> board;
    public:
        SnakesAndLadders() : n_players(0), n_board(0), players(), board() {}
        SnakesAndLadders(int n,int N) : n_players(n), n_board(N), players(n), board(N) {for(int i =0; i<N; i++) {board[i]=i;} }
        int roll_die(std::mt19937 &) const;
};



#endif

And in my.cpp:在 my.cpp 中:

#include "blabla.hpp"

int SnakesAndLadders::roll_die(std::mt19937 & gen) const {
    std::uniform_int_distribution<int> U(1,6);
    int dice = U(gen);
    return dice;
}

And for my test.cpp:对于我的 test.cpp:

#include "blabla.hpp"
#include <fstream>
#include <string>


int main() {
     std::mt19937 G(time(NULL));
    double moy=0;
    for(int i=0; i<100; i++) {
        moy+=roll_die(G);
    }
    moy=moy/100;
    return 0;
}

And I have the following error:我有以下错误:

'roll_die' was not declared in this scope moy+=roll_die(G); 'roll_die' 未在此 scope moy+=roll_die(G) 中声明;

roll_die is declared in the.hpp, so I don't understand the error. roll_die 在.hpp 中声明,所以我不明白错误。

roll_die is declared as a SnakesAndLadders object function. roll_die被声明为SnakesAndLadders object function。 To use it you would first have to create a SnakesAndLadders object要使用它,您首先必须创建一个SnakesAndLadders object

SnakesAndLadders snl;
snl.roll_die(G);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM