Calling member of one class in another

后端 未结 1 1906
[愿得一人]
[愿得一人] 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)
提交回复
热议问题