Where have I specified a return type for a constructor?

Hello,

I have 2 classes, one parent and a derived one. I receive the error where i get the following


"
return type may not be specified on a constructor
"

in line 157. My code will obviously not compile.

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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#pragma


#ifndef STUDENTSDEF 
#define STUDENTSHEADERDEF

#include <string> 
#include <iostream>

using namespace std;

class Student
{
	private:
		double mlibrary_Fine;
	public: 
		string mName;
		double mtuition_Fees;

		//Default Constructor
		Student();
		
		//over-ridden constructor
		Student(string, double, double);

		//Copy constructor
		Student(const Student&);

		//Destructor
		~Student();

		//Assignment operator
		Student& operator=(const Student&);

		//To show the details of the student as output.
		void showStudent();
		//Method to calculate the total money.
		double calculateTotal();

		//Method to enter the details of the student.
		void enterDetails();

		/*The library fines owed by the students must be a nonnegative number. Enforce this by making a student’s library fines a private 
		member of the class. Write one method that allows the user to set this variable only to nonnegative values, and another method that 
		can be used to access this private variable. Both methods should be public members of the class.*/

		//Method to set value for library fine
		void SetLibraryFine();

		//Method to view the library fine
		void ViewFine();

		//Friend function to pass library fine by reference
		friend double* passLibraryFine(Student&);
}; 
//Default constructor
Student::Student()
{
	mName = "John";
	mlibrary_Fine = 0.0;
	mtuition_Fees = 0.0;
}

//Over-ridden constructor
Student::Student(string Name, double fines, double  fees)
{
	mName = Name;
	mlibrary_Fine = fines;
	mtuition_Fees = fees;
}
//Copy Constructor
Student::Student(const Student& otherStudent)
{
	Student A;
	
	mName = otherStudent.mName;
	mlibrary_Fine = otherStudent.mlibrary_Fine;
	mtuition_Fees = otherStudent.mtuition_Fees;
}

//Overloading the assignment operator. 
Student& Student::operator=(const Student& anotherStudent)
{
	mName = anotherStudent.mName;
	mlibrary_Fine = anotherStudent.mlibrary_Fine;
	mtuition_Fees = anotherStudent.mtuition_Fees;

	return *this;
}

//Destructor
Student::~Student()
{

}

//Method to show details of the student.
void Student::showStudent()
{
	cout << "Name of student = "<< mName << endl;
	cout << "Library Fines = " << mlibrary_Fine << endl;
	cout << "Fees = " << mtuition_Fees << endl;
}

//Method to calculate the total money owed by the student. 
double Student::calculateTotal()
{
	double total;

	total = mlibrary_Fine + mtuition_Fees;

	return total;
}

//Method to change the member variables of the student object. 
void Student::enterDetails()
{

	cout << "What is the name of the student?" << endl;
	getline(cin, mName);
	
	cout << "What is the total fines for the student?" << endl;
	cin >> mlibrary_Fine;

	cout << "What are the total fees for the student ?" << endl;
	cin >> mtuition_Fees;
}

void Student::SetLibraryFine()
{
	do
	{
		cout << "What is the value for the library fine? Ensure it isn't a negative value " << endl;
		cin >> mlibrary_Fine;

		if (mlibrary_Fine <= 0)
		{
			cout << "You entered a negative value, re-enter a positive value " << endl;
			cin >> mlibrary_Fine;
		}

	} while (mlibrary_Fine <= 0);

	cout << "You have set the value of the fine to " << mlibrary_Fine << endl;
}

void Student::ViewFine()
{
	cout << "The total value of the fines is " << mlibrary_Fine << endl;
}

/*3. Students at the university are either graduate students or undergraduate students. All undergraduate students
are full-time students. Graduate students may be fulltime students or part-time students. Derive a class of graduate
students from the class of students that you have already written with an additional member variable that stores
whether the student is full-time or part-time.*/

class GraduateStudent : public Student
{
public:
	char time;
	GraduateStudent();
	GraduateStudent(char, string, double);

	/*4. Graduate students do not pay tuition fees. Use polymorphism to write a method that calculates the
	total money owed by a graduate student. This will require the method for calculating the total money owed
	to be a virtual function of the parent class.*/
	virtual double calculateTotal(Student&);
	friend double* passLibraryFine(Student&);
}

GraduateStudent::GraduateStudent()
{
	time = 'N';
	mName = "unspecified";
}

GraduateStudent::GraduateStudent(char t, string Nm, double f)
{
	time = t;
	mName = Nm;
	mtuition_Fees = f;
}

double GraduateStudent::calculateTotal(Student& Std)
{
	double total = 0.0;
	double fine = *passLibraryFine(Std);
	total = total + fine;

	return total;
}

double* passLibraryFine(Student& Std)
{
	double* p_fine = &Std.mlibrary_Fine;

	return p_fine;
}

#endif 


Last edited on
Hello Shishykish,

Did you forget something on line 169?

Andy
@HandyAndy

ARRGHHH! Bloody semi-colon! Thanks, compiles well now.
Hello Shishykish,

It is the little things that cause the biggest problems.

Andy
Topic archived. No new replies allowed.