473,657 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

circular includes/in file problems

3 New Member
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 1621
DumRat
93 New Member
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
Saltydog
3 New Member
yeah there is one, I just didnt copy that far down soz :S
Oct 17 '07 #3
Saltydog
3 New Member
...bump.....

plz anyone?
Oct 24 '07 #4
gpraghuram
1,275 Recognized Expert Top Contributor
...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 Recognized Expert Moderator Expert
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
5241
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 module C and some other modules
2
1815
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 mod_python/Apache and PSP programming. Can anybody tell me if there are any situations where circular imports cause problems and, other than a redesign to eliminate it, if there are any other ways around those problems ?
1
2289
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
2819
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 Server Pages Event Category: None Event ID: 9 Date: 09/07/2004 Time: 09:29:25
3
2043
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
2828
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 semi-circular definitions and
6
2824
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 stumped again with this little love triangle. Here is some background: m_commands.h defines - struct command_callbacks, which contains - a struct conn * reference - struct command, which contains - a struct command_callback reference
3
6228
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 */ struct type2; typedef struct type1
3
2915
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 better than the amount of errors I was originally getting on builds before I consilidated by UC's though :-) "Paul Hale" wrote:
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.