Accessing varaibles from other classes

0 Lé Pig · May 9, 2015
#include <iostream>
#include <random>
#include <ctime>

using namespace std;

class diceRoller{

    int randomGenerator(){

    mt19937 randGen (time(NULL));
    uniform_int_distribution <int> numberRoll(2, 12);
    int results = numberRoll(randGen);
    cout << results;

class playerClass{

    int dealerFunction(){

    int pocketMoney;
    int bet;

    cout << "How much would you like to bet?\n$";
    cin >> bet;
    if (results <= 5){
    pocketMoney -= bet;





int main()

playerClass playerObject;


How can I access the variable "results" from the class "diceRoller" and use it in the class "playerClass"? I know I can combine classes or not use them at all but this is only for practice sake so I'm not trying to create some elaborate program that will stand the test of time. And sorry for not using the "code" tool to make it easier to read. For some reason it only allows me to paste about half of this if I use that.

Post a Reply


Oldest  Newest  Rating
0 Lé Pig · May 9, 2015
Do you mean something like this?

   static int randomGenerator(){
    mt19937 randGen (time(NULL));

    int numberSeeding(){
    uniform_int_distribution diceRoll(2, 12);
    int results = diceRoll(randomGenerator());
0 Lé Pig · May 9, 2015
Why am I getting an error that says
no match for call to '(std::uniform_int_distribution) (int)'
0 Lé Pig · May 10, 2015
I'm not sure. I just changed the one function to two and then tried to run it and that's what came up.
0 Lé Pig · May 10, 2015
Sorry, I'm not sure I understand your question. At which point am I trying to call a function operator that doesn't exist?
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator