Error: no idea what the error

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
class alarm
{
private:
	int RTime;
	bool alarmOn;

public:
	alarm(bool, int);
	alarm();
	void setRTime(int);
	void setAlarm(bool);
	string display();
}

alarm::alarm(bool aOn, int rt) //error HERE
{	
	alarmOn = aOn;
	RTime = rt;
	cout << "2nd Constructor with 2 argument" << endl;
}

alarm::alarm()
{
	alarmOn = false;
	RTime = 2400;
	cout << "default Constructor" << endl;
}

void alarm::setAlarm(bool aOONN)
{
	alarmOn = aOONN;
}

void alarm::setRTime(int rtt)
{
	RTime = rtt;
}

string alarm::display()
{
cout << alarmOn;
cout << RTime;
}

int main()
{
	alarm A1; 
	alarm A2(false,0); // error HERE, 0 for alarmOn and 0 for RTime.

A1.display();
A2.display();

A1.setAlarm(true);
A1.setRTime(1350);
A1.display();
}


line 15: error C2533: 'alarm::{ctor}' : constructors not allowed a return type
error C2264: 'alarm::alarm' : error in function definition or declaration; function not called
semicolon missing line 13
i am so careless. tks.
closed account (z05DSL3A)
alarm::display() should also return a string.
Is there an explanation, due to how the compiler parses C++, of why ";" is required after a class definition but not after a function/method definition? Couldn't the compiler just as well assume ";" even if it's not there, as soon as a closing bracket for a class definition is encountered? And if it can assume that, why require it?

Not complaining (I love C++)... just curious. I'm sure there's a reason, I just don't see it.
Topic archived. No new replies allowed.