Problems with includes/object of a different class as a private member

In trying to make a simple emergency room simulation I'm having some errors compiling. I want an array of PatientType objects as a private member of my ArrayType class where I initialize it in ArrayType's default constructor but I'm getting "In file included from errors" just by including ArrayType.h in it's .cpp and also in ArrayType.h it doesn't know what a PatientType object is.

To shorten the post I've removed several methods from ArrayType and most of main but I thought this would accomplish creating a new ArrayType object and adding a PatientType object to its array, still doesn't work =/

ArrayType.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef ARRAYTYPE_H
#define	ARRAYTYPE_H
using namespace std;

class ArrayType {
    
public:
    ArrayType();
    ~ArrayType();
    void addPatient(PatientType P);
    
private:
    PatientType ERList;
    int SIZE;
    int numPatients;
};

#endif 

ArrayType.cpp:
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
#include "ArrayType.h"
using namespace std;

ArrayType::ArrayType() {
    SIZE = 300;
    ERList = new PatientType[SIZE];
    numPatients = 0;
}

ArrayType::~ArrayType() {
    delete [] ERList;
}

void ArrayType::addPatient(PatientType P) {
    if (numPatients == 0) {
        ERList[0] = P;
    } else  if (P < ERList[numPatients-1]) {
        ERList[numPatients] = P;
    } else {
        for (int i = 0; i < numPatients; i++) {
            if (P > ERList[i]) {
                for (int j = numPatients-1; j >= i; j--) {
                    ERList[j+1] = ERList[j];
                }
                ERList[i] = P;
                break;
            }
        }
    }
    numPatients++;
}

PatientType.h:
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
#ifndef PATIENTTYPE_H
#define	PATIENTTYPE_H
using namespace std;

class PatientType {
    
public:
    PatientType(string lName, string fName, string insurance, int priority, int arrivalTimeHr, int arrivalTimeMin);
    ~PatientType();
    string getFirstName() const;
    string getLastName() const;
    int getPriority() const;
    int getArrivalTimeHr() const;
    int getArrivalTimeMin() const;
    
    bool operator<(const PatientType& other);
private:
    string lName, fName, insurance;
    int priority, arrivalTimeHr, arrivalTimeMin;
    
    bool PatientType::operator <(const PatientType& other) const {
        if ((*this).getPriority() != other.getPriority()) {
            return ((*this).getPriority() < other.getPriority());
        } else {
            if ((*this).getArrivalTimeHr() != other.getArrivalTimeHr()) {
                return ((*this).getArrivalTimeHr() < other.getArrivalTimeHr());
            } else {
                return ((*this).getArrivalTimeMin() < other.getArrivalTimeMin());
            }
        }
    } // > operator is also overloaded, just trying to shorten post
};

#endif 

PatientType.cpp:
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
#include "PatientType.h"
using namespace std;

PatientType::PatientType(string lName, string fName, string insurance, int priority, int arrivalTimeHr, int arrivalTimeMin) {
    this->lName = lName;
    this->fName = fName;
    this->insurance = insurance;
    this->priority = priority;
    this->arrivalTimeHr = arrivalTimeHr;
    this->arrivalTimeMin = arrivalTimeMin;
}

PatientType::~PatientType() {
}

string PatientType::getFirstName() const {
    return fName;
}

string PatientType::getLastName() const {
    return lName;
}

int PatientType::getPriority() const {
    return priority;
}

int PatientType::getArrivalTimeHr() const {
    return arrivalTimeHr;
}

int PatientType::getArrivalTimeMin() const {
    return arrivalTimeMin;
}

main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "ArrayType.h"
#include "PatientType.h"
using namespace std;

int main(int argc, char** argv) {

    ArrayType ER = new ArrayType();
    PatientType newP = new PatientType("some", "some", "some", 75, 10, 30);
    ER.addPatient(newP);

    return 0;
}
> but I'm getting "In file included from errors"
http://www.cplusplus.com/forum/articles/40071/#msg216270


http://www.cplusplus.com/forum/articles/10627/ (4)
ArrayType.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef ARRAYTYPE_H
#define	ARRAYTYPE_H
#include "PatientType.h"
//using namespace std; //this would pollute anything that includes it

class ArrayType {
    
public:
    ArrayType();
    ~ArrayType();
    void addPatient(PatientType P);
    
private:
    PatientType ERList;
    int SIZE;
    int numPatients;
};

#endif  


main.cpp
1
2
3
4
5
6
7
8
9
10
11
#include "ArrayType.h"
#include "PatientType.h"
using namespace std; //no problem to put it here, it would only affect this tu

int main(int argc, char** argv) {
    ArrayType ER; //creating an object using the default constructor
    PatientType newP("some", "some", "some", 75, 10, 30); //creating an object using a non-default constructor
    ER.addPatient(newP);

    return 0;
}
Topic archived. No new replies allowed.