473,399 Members | 2,159 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,399 software developers and data experts.

strange ) expected error

112 100+
i have this code in the header of one of my classes:

Expand|Select|Wrap|Line Numbers
  1. bool hasWorker;
  2. void assignWorker(Civilian *);
  3. Civilian *myWorker;
is something wrong with that that i am not noticing i keep getting a :

[C++ Error] Job.h(19): E2293 ) expected

on the void assignWorker(Civilian *); line...

the civilian class was included at the top of the header as so:

Expand|Select|Wrap|Line Numbers
  1. #ifndef Job_h
  2. #define Job_h
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include "Civilian.h"
im actually experiencing a similar problem in the Civilian class here:

Expand|Select|Wrap|Line Numbers
  1.    void giveJob(Job *);
  2.    void advanceTask();
they accomplish similar things so i assume the problem may be related?

thanks
ken
Nov 27 '07 #1
15 2083
Meetee
931 Expert Mod 512MB
i have this code in the header of one of my classes:

Expand|Select|Wrap|Line Numbers
  1. bool hasWorker;
  2. void assignWorker(Civilian *);
  3. Civilian *myWorker;
is something wrong with that that i am not noticing i keep getting a :

[C++ Error] Job.h(19): E2293 ) expected

on the void assignWorker(Civilian *); line...

the civilian class was included at the top of the header as so:

Expand|Select|Wrap|Line Numbers
  1. #ifndef Job_h
  2. #define Job_h
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include "Civilian.h"
im actually experiencing a similar problem in the Civilian class here:

Expand|Select|Wrap|Line Numbers
  1.    void giveJob(Job *);
  2.    void advanceTask();
they accomplish similar things so i assume the problem may be related?

thanks
ken
What about Civilian? Is it defined? Is there any other error along with this?
Nov 28 '07 #2
drsmooth
112 100+
the Civilian class is defined with a header and cpp files and every function is defined in the cpp.

im getting other errors but theyre all after that one and it seems the ) expected is causing the other two...
Nov 28 '07 #3
drsmooth
112 100+
i noticed a peculiar thing happening maybe someone could explain... all my code compiles perfectly fine until i include the civilian header.
Expand|Select|Wrap|Line Numbers
  1.    void giveJob(Job &);
  2.    void advanceTask();
  3.    Job myJob;
that code works just fine and compiles but as soon as i add:
Expand|Select|Wrap|Line Numbers
  1. #include "Civilian.h"
to the Job class header,

Expand|Select|Wrap|Line Numbers
  1. void giveJob(Job &);
gives me this error:

[C++ Error] Civilian.h(29): E2293 ) expected


may it have something to do with methods set up to take each other as parameters?

e.g i have a
giveJob(Job&);
in the civilian class, and i have a assignWorker(Civilian *) in the job class

could that be thr problem? i seem to think it cant be...
Nov 28 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Do you have a null line at the end of Civilian.h??

You may have to post your header so we can see what line 29 is about. The error is there or earlier in the file.
Nov 28 '07 #5
drsmooth
112 100+
the contens of my civilian header are as follows:

Expand|Select|Wrap|Line Numbers
  1. #ifndef Civilian_h
  2. #define Civilian_h
  3. #include <iostream>
  4. #include <string>
  5. #include "Job.h"
  6. using namespace std;
  7. class Civilian
  8. {
  9.   public:
  10.    static long nextID;
  11. //-------------------------
  12. //--constructors-----------
  13.    Civilian();
  14.    Civilian(int);
  15. //-------------------------
  16. //--public member variables
  17.    long myID;
  18.    bool isAlive, hasJob, hasHouse;
  19.    int daysWithoutFood;
  20.    string pronoun;
  21. //------------------------------------
  22. //--methods involved in daily activity
  23.    void age(int);
  24.    bool eat(int,int);
  25.    void advanceDay();
  26.    void satisfy(int);
  27. //--------------------------------
  28. //--methods involved in working
  29.    void giveJob(Job &);
  30.    void advanceTask();
  31.    Job myJob;
  32. //--------------------------------
  33. //--methods to access private members
  34.    const string getName(){return name;}
  35.    const string getCivString();
  36.    const int getSatisfaction(){return satisfaction;}
  37.   private:
  38. //--identification
  39.    void assignName();
  40.    string name;
  41.    char gender;
  42.    int ageDays,ageMonths,ageYears;
  43. //--statistical
  44.    long totalFoodConsumed;
  45. //--pertinant to other calculations
  46.    int satisfaction;
  47.   public:
  48.    static string itos(int);
  49.    string getAgeMDY();
  50.    string getIsEmp();
  51. };
  52. #endif
  53.  
Nov 28 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
I compiled OK using your Civilian.h and this main() with Visual Studio.NET 2005:
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.      bool hasWorker;
  4.      void assignWorker(Civilian *);
  5.      Civilian *myWorker;
  6.  
  7. }
  8.  
All I had to do was create an empty class Job.

I did get a warning here:
Expand|Select|Wrap|Line Numbers
  1. const int getSatisfaction(){return satisfaction;}
  2.  
A function that returns an int does not need to make that int a const. The compiler ignores the const. Only when you return a pointer or a reference does this make sense.

So I don't know where that leaves you.
Nov 29 '07 #7
drsmooth
112 100+
the strange thing is the error is a ') expected' i feel like that should be a syntax error but i dont see that there is any problem...

i've tried changing just about anything related to this functoin and the error goes away when i remove the #include "Civilian.h" from the job class

its just strange....
Nov 29 '07 #8
weaknessforcats
9,208 Expert Mod 8TB
Maybe it's time to look at your Job.h.
Nov 30 '07 #9
drsmooth
112 100+
would you like me to post it? or was that a directive to look at it myself?


i looked it over and nothing looked bad to me but if i knew what the problem was i wouldnt have to bother you guys...
Nov 30 '07 #10
weaknessforcats
9,208 Expert Mod 8TB
Post it. I'm curious now.

I intend to compile your code using Visual Studiuo.NET 2005.
Dec 1 '07 #11
drsmooth
112 100+
Expand|Select|Wrap|Line Numbers
  1. #ifndef Job_h
  2. #define Job_h
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include "Civilian.h"
  8. using namespace std;
  9. using std::vector;
  10.  
  11. class Job
  12. {
  13.   public:
  14.     Job(string, int);
  15.     Job();
  16.     void accomplishTime();
  17.     string getName();
  18.     string getActiveTask();
  19.     bool hasWorker;
  20.    Civilian *myWorker;
  21.   private:
  22.     void analyzeDataFile();
  23.     int destination, pos, taskCount;
  24.     vector<int> taskTimes;
  25.     vector<string> taskNames;
  26.     int goodsPerCycle, startDelay, taskTimeRemaining;
  27.   public:
  28.     int activeTask;
  29.     string jobName;
  30. };
  31. #endif
this is the original version, i had to comment out line 20 because i gave me this error:

[C++ Error] Job.h(20): E2303 Type name expected

i use borland c++ builder

thanks alot
Dec 1 '07 #12
weaknessforcats
9,208 Expert Mod 8TB
Line 20 is Civilian* myWorker and your compiler is complaining that Civilian is not a type. That is, the compiler has not seen the Civilian class yet.

This is caused by including Job.h inside Civilian.h. The Job.h is included before the Civilian class declaration.

Use a forward reference in your Job.h:
Expand|Select|Wrap|Line Numbers
  1. class Civilian;  //forward reference
  2. class Job{
  3. {
  4.    Civilian* myWorker;
  5. };
  6.  
and the error will go away. The forward refercence is enough information for the compiler to allow a Civilian*. More than that, and you will need the entire Civilian class declaration.
Dec 2 '07 #13
drsmooth
112 100+
what would that "forward reference" do? how do they work?

that will probably fix the other problems i was having as well

thank you
Dec 2 '07 #14
weaknessforcats
9,208 Expert Mod 8TB
The rule is: You cannot use a type before you declare it.

Therfore this code:
Expand|Select|Wrap|Line Numbers
  1. class Job
  2. {
  3.     Civilian* myWorker;
  4. };
  5.  
cannot compile unless you have declared Civilian as a type already. You do this by preceding this code with the struct or class definition of Civilian.

However, if all you need is a Civilian*, then rthe compiler does not need to see the actual struct/class declaration. You can abbreviate by:
Expand|Select|Wrap|Line Numbers
  1. class Civilian;   //forward reference
  2. class Job
  3. {
  4.     Civilian* myWorker;
  5. };
  6.  
This forward reference tells the compiler that there is a struct/class Civilian but it hasn't been encountered yet. That assurance is enough for the compiler to allow a Civilian*.

You need this in those situations where class Job has a Civilian* and class Civilian has a Job*. Not that this is your case but without the forward reference this situation could never be compiled.
Dec 3 '07 #15
drsmooth
112 100+
ok yea that definitely fixed the problems...thanks alot
Dec 4 '07 #16

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

Similar topics

8
by: Peng | last post by:
Hi, I have encountered a simple but strange problem recently, with the STL vector. When I tried to compile a code like this, the compiler flags an error: Error 212: "small.cc", line 200 #...
3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
1
by: Nadav | last post by:
I have a strange problem with inherited controls: I have created two user controls called UserLoginA & UserLoginB. One of the properties of these controls is of type UserGroup ( a class I...
2
by: P | last post by:
Hi all, I'm trying to run the following code taken from http://blogs.ittoolbox.com/database/technology/archives/006045.asp# select substr(tablespace_name,1,30) as "Tablespace Name", case...
11
by: Dagwood Bumstead | last post by:
I play around with js a little... I just don't get this. The file below is just trying out some things... it does exactly what I want (hides/displays some things, no big deal) The problem is...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
7
by: ChrisM | last post by:
I posted this last week, so apologies for re-posting but I'm still looking for a sensible answer, and I'm hoping somone new might be able to cast some light... Basically, I have a fairly...
0
by: maryjones11289 | last post by:
Hi, I have a strange problem that hopefully someone can advise me on... I have a Gridview which is not bound to a dataset etc. I populate the gridview manually by constructing my own table,...
2
by: reinisr | last post by:
Hi! This program: template<class T_index, class T_data> class AAA { public: AAA(int ii = 0,int jj = 0) {} };
1
by: jbitz | last post by:
Hi, This has got me really baffled. This has got me really baffled. When I run Dim url As String = HttpContext.Current.Request.Url.AbsolutePath.ToLower from Application_beginRequest in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.