Header file problems, maybe?

I have two classes, ToDo and Family. In one of the ToDo constructors I am passing in a Family object from main (pass by address). This is the code.

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
ToDo::ToDo(Family* famList)
{	
	cout << "\nCreating ToDo...\n";
	cout << "\nChecking for appts.txt file...\n";

	ifstream apptFile("c:\\appts.txt");
	if(apptFile.is_open())
	{
		cout << "\nFile found.\n";
		cout << "\nRealizing appt.txt...\n";

		for(int k = 0;!apptFile.eof();++k)
		{
			Person p;
			time_t time;
			char s1[SHRTNAME];
			
			apptFile >> time;
			apptFile >> s1;

			Date d(time);
			p = famList.search(s1); //compile error "famList not part of class"			
			Appointment a(&p, d);
			addAppt(&a);
		}
	}

	else
		cout << "\nFile not found.\n";

	apptFile.close();
}


I keep getting the compile error that famList needs to be part of a class. I believe the problem being with the header files and ToDo not being aware of the Family class, but I've added a #include family.hpp in the todo.hpp, yet I'm still receiving the same compile error. Here's my todo.hpp file in case it helps pinpoint the problem.

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
#ifndef TODO_H
#define TODO_H
#include "cell.hpp"
#include "family.hpp"

class ToDo {
	friend class Cell;
	private://-------------------------------------------------------------------------------------------------------------------------
		Cell* head;
		Cell* scan;
		Cell* follow;
		Cell* found;
		int numCells;
		Cell* find(const int, const int, const int, const int, const int);
	public://--------------------------------------------------------------------------------------------------------------------------
		ToDo(Family*);
		~ToDo();
		int Count();
		void addAppt(Appointment*);
		void seeAppts(const int, const int, const int, const int, const int);
		void killAppt(ToDo);
		void print(ostream&);
		void printFile(ofstream&);
		void archive(ToDo);
		inline Cell* operator++(){scan = scan->next; return scan;}
};
inline ostream &operator<<(ostream &stream, ToDo& o);
#endif 


I'm truly stumped on this. Any help is appreciated and please let me know if you need any additional code from my project. Thanks in advance!
Last edited on
 
p = famList.search(s1);



famList is an address (pointer) so it needs de-referencing like this:


 
p = famList->search(s1);

/facepalm

Would this fix my original compile error though? I'd try to run it right now but I'm not home. Is not de-referencing the object causing the "needs to be part of a class" error?
Last edited on
I don't know. Have you declared class Family to the compiler before it tries to compile this chunk of code?
Edit: Yup, de-referencing the object fixed it, it compiles now. It crashes at the ToDo constructor, but I just need to debug my newly added code now :p

Thanks again!
Last edited on
Topic archived. No new replies allowed.