Calling member of one class in another

后端 未结 1 1905
[愿得一人]
[愿得一人] 2021-01-29 05:58

For an assignment I\'m required to create a game using die rolls that uses multiple classes. For Dice.cpp I i wrote a function that just gets a random die roll from

1条回答
  •  伪装坚强ぢ
    2021-01-29 06:54

    You need to either create an instance of Dice to call the method on like this

    Dice d;
    roll = d.getRoll();
    

    or you need to make getRoll static. In the function declaration in Dice.h you'd put

    static int getRoll();
    

    and you would use it like this

    roll = Dice::getRoll();
    

    0 讨论(0)
提交回复
热议问题