Build errors are being thrown on class definitions

I'm trying to design a class to be able to accept various input and then return the values. Every time I build it, it complains about unknown override specifiers or unexpected tokens. I'm not sure if I'm failing to properly declare a variable or an include somewhere. Here's my code, some errors are commented in.

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
// Header file
#ifndef PATIENT_H_
#define PATIENT_H_
#include <string>

class Patient {
public:
	Patient();
	Patient(string, int, int, double, int, string);
	~Patient();
	string getPatientName() const;
	int getPatientAge() const;
	int getPatientHeight() const;
	double getPatientWeight() const;
	string getPatientGender(int newPatientGender) const;
	string getPatientDisease() const;
	void printInfo() const;

private:
	string newPatientName;    //error: unknown override specifier
	int newPatientAge;
	int newPatientHeight;
	double newPatientWeight;
	int newPatientGender;
	string newDisease;     //error: unknown override specifier
                               // another error: missing type specifier, int assumed
};

#endif 

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
// Function definitions
#include "Patient.h"
using namespace std;

Patient::Patient() {
	newPatientAge = 0;
	newPatientHeight = 0;
	newPatientWeight = 0.0;
	newPatientGender = 0;
}
Patient::Patient(string patientName, int patientAge, int patientHeight, double patientWeight, int patientGender, string disease) {
	newPatientName = patientName;
	newPatientAge = patientAge;
	newPatientHeight = patientHeight;
	newPatientWeight = patientWeight;
	newPatientGender = patientGender;
	newDisease = disease;
}
Patient::~Patient() {}
string Patient::getPatientName() const {
	return newPatientName;
}
int Patient::getPatientAge() const {
	return newPatientAge;
}
int Patient::getPatientHeight() const {
	return newPatientHeight;
}
double Patient::getPatientWeight() const {
	return newPatientWeight;
}
string Patient::getPatientGender(int newPatientGender) const {
	if (newPatientGender == 0)
		return "Male";
	else if (newPatientGender == 1)
		return "Female";
	else
		return "Unspecified";
}
string Patient::getPatientDisease() const {
	return newDisease;
}
void Patient::printInfo() const {
	cout << "Patient: " << getPatientName() << endl;
	cout << "Age: " << getPatientAge() << endl;
	cout << "Height (in.): " << getPatientHeight() << endl;
	cout << "Weight (lbs.): " << getPatientWeight() << endl;
	cout << "Gender: " << getPatientGender(newPatientGender) << endl;
	cout << "Disease: " << getPatientDisease() << endl;
}

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
#include <iostream>
#include <string>
#include "Patient.h"

using namespace std;

int main() {

	string patientName;
	int patientAge;
	int patientHeight;
	double patientWeight;
	int patientGender; 
	string disease;


     /* it may or may not be worth noting that even without the cout / cin 
  statements and placing actual values in the object parameters, it still threw identical build errors.*/

	cout << "Name: ";
	getline(cin, patientName);
	cout << "\nAge: ";
	cin >> patientAge;
	cout << "\nHeight: ";
	cin >> patientHeight;
	cout << "\nWeight: ";
	cin >> patientWeight;
	cout << "\nGender: 0 for male, 1 for female ";
	cin >> patientGender;
	cout << "Ailments: ";
	cin >> disease;

	Patient genericPerson(patientName, patientAge, patientHeight, patientWeight, patientGender, disease);   
//no overloaded function takes 6 arguments
	genericPerson.printInfo();
	system("Pause");
	return 0;
}
Last edited on
Hi,

Please post the exact compile output.


Edit:
You didn't have using namespace std;

But this is a bad idea anyway, put std:: before each std thing, notice that all the expert coders here all do that. Google to see why.
Last edited on
Hi,

You didn't have using namespace std;

But this is a bad idea anyway, put std:: before each std thing, notice that all the expert coders here all do that. Google to see why.

Some things I noticed, mostly to do with style:



6
7
8
9
10
11
12
13
14
15
16
17
18
class Patient {
public:
	Patient() = default; //does the same thing as what your code does - sets them all to zero.
	Patient(string, int, int, double, int, string); 
        // provide names for the parameters & make them const, anything not POD use a reference
        // not an error your way, but better this way
        Patient(const std::string&  Name, 
                   const unsigned int AgeInYears,        
                   const unsigned int HeightInches, // or cm, could use std::size_t, or something from cstdint.h
                   const double         WeightPounds ,  // or Kg
                   const char             Gender, 
                   const std::string&   Disease);



With this, don't put the class name in the variable names, new is superfluous
19
20
21
22
23
24
25
private:
	std::string   Name;    
	int              Age;
	int              Height;
	double        Weight;
	int              Gender;
	std::string   Disease;
Last edited on
Hi again,

Some other things:

Consider using a ctor initialiser list.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Patient::Patient(const std::string& Name, 
                        const std::size_t Age, 
                        const std::size_t tHeight, 
                        const double Weight, 
                        const char tGender, 
                        const string& Disease)
           :    // colon introduces initialiser list
           Name ( Name),
	   Age ( Age),
	   Height  ( Height),
	   Weight ( Weight),
	   Gender ( Gender),
	   Disease ( Disease)
 {
	// nothing to do here, unless you want to do validation & throw exception if problems
}


If you don't provide any functionality in your destructor, don't provide one at all, an implicit one will be created.
Topic archived. No new replies allowed.