Function of Class Overload Return Type Error

Howdy,

I'm stumbling with functions of classes. My code is for a dice game but I can't even get the basic function of dice rolling to work. With the code below I get the following error:

error C2556: 'Die Die::DieReport(void)' : overloaded function differs only by return type from 'int Die::DieReport(void)'

see declaration of 'Die::DieReport'

error C2371: 'Die::DieReport' : redefinition; different basic types

see declaration of 'Die::DieReport'


Any help on this or even any comments or observations on how to improve the structure are greatly appreciated, thanks. :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;
 

int counter = 0;
int rollChoice = 0;
int mainMenuChoice = 1;

class Die;

void rollDice(Die die1, Die die2, Die die3, Die die4, Die die5);
void rollTest(Die die1, Die die2, Die die3, Die die4, Die die5);

class Die
{
public:	
	int dieNumber;
	bool held;
	int pips;

	bool Holding();
	int DieReport();
	int Roll();
}

int Die::DieReport()
{
	cout<< "Die #" << dieNumber << " is now showing " << pips << " pips." << endl << endl;
	return pips;
}

bool Die::Holding()
{
	if(held == false)
	{
		held = true;
		cout<< "Die #" << dieNumber << " is now held." << endl << endl;
	}
	else
	{
		held = false;
		cout<< "Die #" << dieNumber << " is now released." << endl << endl;
	}

	return held;
}

int Die::Roll()
{
	srand(static_cast<unsigned int>(time(0)));

	int randNum = rand();
	pips = (randNum % 6) + 1;
	return pips;
}


void main()
{

	Die die1;
	die1.dieNumber = 1;
	die1.held = false;
	die1.pips = 1;
	Die die2;
	die2.dieNumber = 2;
	die2.held = false;
	die2.pips = 1;
	Die die3;
	die3.dieNumber = 3;
	die3.held = false;
	die3.pips = 1;
	Die die4;
	die4.dieNumber = 4;
	die4.held = false;
	die4.pips = 1;
	Die die5;
	die5.dieNumber = 5;
	die5.held = false;
	die5.pips = 1;

	cout<< "Die Test"<< endl<<endl;
	cout<< "1. Launch"<< endl<<endl;
	cout<< "2. End"<< endl<<endl;
	cin >> mainMenuChoice;

	while(mainMenuChoice == 1)
	{
	cout<< "Die Test"<< endl<<endl;
	cout<< "1. Launch"<<endl;
	cout<< "2. End"<< endl<<endl;
	cin >> mainMenuChoice;		
	
	rollTest(die1, die2, die3, die4, die5);
	
	}
	cout<< "Bye" << endl;
	system("pause");
}

void rollDice(Die die1, Die die2, Die die3, Die die4, Die die5) 
{ // rolls dice
	die1.Roll();
	die2.Roll();
	die3.Roll();
	die4.Roll();
	die5.Roll();




}

void rollTest(Die die1, Die die2, Die die3, Die die4, Die die5)
{
	rollDice(die1, die2, die3, die4, die5);

	//more to be added later
}


You're missing a semicolon on line 27.

Line 61 should really be int main() and you should return a number from it.

Move line 53 to the beginning of main. There is no need to call srand more than once in a program.
Topic archived. No new replies allowed.