473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

circular includes/in file problems

Ok so I ahve spent a while reading around this site and some others, and I thought there might of been some errors with my includes, but now I am just really confused. Basically I have a 3 classes, a main class and 2 sub classes the sub classes point at each other, but interactions is no more then pointing.

In the main program I have #include "school.h" in the header. I have the error

from schoolMain.cpp In file included from school.h:5, from schoolMain.cpp

some common other errors are:

student.h expected unqualified-id before '.' token

student.h variable or field `setID' declared void

from what I've read, this is either a include error or a syntax error. the code for school is:

Expand|Select|Wrap|Line Numbers
  1. #ifndef school_H
  2. #define school_H
  3.  
  4. #include <string>
  5. #include "student.h"
  6. #include "unit.h"
  7.  
  8. class school
  9. {
  10.       public:
  11.              School() {myStudents.resize(1); myUnits.resize(1)};
  12.              ~School();
  13.              void addStudentUnit(string studentName, string unitName);
  14.              void printUnitsOfStudent(string studentName) const;
  15.              void printStudentsOfUnit(string unitName) const;
  16.              bool studentExists(string studentName, int &size);
  17.              bool unitExists(string unitName, int &size)
  18.  
  19.       private:
  20.               vector<student> myStudents();
  21.               vector<unit> myUnits;    
  22. }
  23.  
  24. #endif
  25.  
I'm thinkin the error is pointing to header 5, which is the unit.h

Expand|Select|Wrap|Line Numbers
  1. #ifndef unit_H
  2. #define unit_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. class student;
  8.  
  9. class unit
  10. {
  11.       public:
  12.              unit() {unitName = ""; pupils.resize(1);};
  13.              void setUnitName(string name);
  14.              string getUnitName() const;
  15.              string getPupil();
  16.              void addPupil(student *p);
  17.              void printPupils() const;
  18.       private:
  19.               string unitName;
  20.               vector<student *> pupils;
  21. }
  22.  
  23. #endif
  24.  
Might as well put in the otehr class for safe measure

Expand|Select|Wrap|Line Numbers
  1. #ifndef stu_H
  2. #define stu_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. class unit.h;
  8.  
  9. class student
  10. {
  11.       public:
  12.           student() {id=""; units.resize(1);};
  13.           void setID(string name);
  14.           string getID() const;
  15.           void addUnit(*unit);
  16.           void printUnits() const;
  17.  
  18.       private:
  19.               string id;
  20.               vector<unit *> units;
  21. }
  22.  
  23. #endif
  24.  
any hints are much appreciated. Thank you in advance
Salty
Oct 17 '07 #1
5 1605
DumRat
93
Ok so I ahve spent a while reading around this site and some others, and I thought there might of been some errors with my includes, but now I am just really confused. Basically I have a 3 classes, a main class and 2 sub classes the sub classes point at each other, but interactions is no more then pointing.

In the main program I have #include "school.h" in the header. I have the error

from schoolMain.cpp In file included from school.h:5, from schoolMain.cpp

from what I've read, this is either a include error or a syntax error. the code for school is:

Expand|Select|Wrap|Line Numbers
  1. #ifndef school_H
  2. #define school_H
  3.  
  4. #include <string>
  5. #include "student.h"
  6. #include "unit.h"
  7.  
  8. class school
  9. {
  10.       public:
  11.              School() {myStudents.resize(1); myUnits.resize(1)};
  12.              ~School();
  13.              void addStudentUnit(string studentName, string unitName);
  14.              void printUnitsOfStudent(string studentName) const;
  15.              void printStudentsOfUnit(string unitName) const;
  16.              bool studentExists(string studentName, int &size);
  17.              bool unitExists(string unitName, int &size)
  18.  
  19.       private:
  20.               vector<student> myStudents();
  21.               vector<unit> myUnits;    
  22. }
  23.  
I'm thinkin the error is pointing to header 5, which is the unit.h

Expand|Select|Wrap|Line Numbers
  1. #ifndef unit_H
  2. #define unit_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. class student;
  8.  
  9. class unit
  10. {
  11.       public:
  12.              unit() {unitName = ""; pupils.resize(1);};
  13.              void setUnitName(string name);
  14.              string getUnitName() const;
  15.              string getPupil();
  16.              void addPupil(student *p);
  17.              void printPupils() const;
  18.       private:
  19.               string unitName;
  20.               vector<student *> pupils;
  21. }
  22.  
  23. #endif
  24.  
Might as well put in the otehr class for safe measure

Expand|Select|Wrap|Line Numbers
  1. #ifndef stu_H
  2. #define stu_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. class unit.h;
  8.  
  9. class student
  10. {
  11.       public:
  12.           student() {id=""; units.resize(1);};
  13.           void setID(string name);
  14.           string getID() const;
  15.           void addUnit(*unit);
  16.           void printUnits() const;
  17.  
  18.       private:
  19.               string id;
  20.               vector<unit *> units;
  21. }
  22.  
  23. #endif
  24.  
any hints are much appreciated. Thank you in advance
Salty

Shouldn't there be an #endif at the end of the school.h?
Oct 17 '07 #2
yeah there is one, I just didnt copy that far down soz :S
Oct 17 '07 #3
...bump.....

plz anyone?
Oct 24 '07 #4
gpraghuram
1,275 Expert 1GB
...bump.....

plz anyone?
What is this declaration above class student
class unit.h;
i think u shuld have using unit;

Raghuram
Oct 24 '07 #5
Banfa
9,065 Expert Mod 8TB
In student.h

class unit.h;

should be

class unit;
Oct 24 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: jinal jhaveri | last post by:
Hi All, I have one question regarding circular inheritance I have 3 files 1) A.py , having module A and some other modules 2) B.py having module B and some other modules 3) C.py having...
2
by: Edward Diener | last post by:
Although it may not be good design, I have a situation such that module A imports module B and module B imports module A. This appears to be causing problems when I use Python with...
1
by: Chris S. | last post by:
Consider the sample case: ## a.py import d import b b.App() ## b.py from c import C B = 'B'
4
by: Evelyne | last post by:
On a server W2K, IIS5, I have many messages from ASP : cirdular dependency between types/modules. Which can be the origin of the problem? Example : Event Type: Warning Event Source: Active...
3
by: crichmon | last post by:
Any general advice for dealing with circular dependencies? For example, I have a situation which, when simplified, is similar to: ///////////// // A.h class A { public: int x;
16
by: Kiuhnm | last post by:
Is there an elegant way to deal with semi-circular definitions? Semi-circular definition: A { B }; B { *A }; Circular reference: A { *B }; B { *A }; The problems arise when there are more...
6
by: T Koster | last post by:
After a few years of programming C, I had come to believe that I finally knew how to correctly organise my structure definitions in header files for mutually dependent structures, but I find myself...
3
by: joshc | last post by:
I've found some old posts on this issue but the answer was a bit vague to me. The problem I am trying to solve is the following: /***** a.h ***********/ #include "b.h" /* Forward declaration...
3
by: =?Utf-8?B?UGF1bCBIYWxl?= | last post by:
Moving all User Controls to a single directory has solved my problem - Thanks Eliyahu. That said, I still got one Circular ref error yesterday, rebuilt again and the build was fine? Far far...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.