i have this code in the header of one of my classes: - bool hasWorker;
-
void assignWorker(Civilian *);
-
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: - #ifndef Job_h
-
#define Job_h
-
-
#include <iostream>
-
#include <string>
-
#include <vector>
-
#include "Civilian.h"
im actually experiencing a similar problem in the Civilian class here: - void giveJob(Job *);
-
void advanceTask();
they accomplish similar things so i assume the problem may be related?
thanks
ken
15 2083
i have this code in the header of one of my classes: - bool hasWorker;
-
void assignWorker(Civilian *);
-
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: - #ifndef Job_h
-
#define Job_h
-
-
#include <iostream>
-
#include <string>
-
#include <vector>
-
#include "Civilian.h"
im actually experiencing a similar problem in the Civilian class here: - void giveJob(Job *);
-
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?
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...
i noticed a peculiar thing happening maybe someone could explain... all my code compiles perfectly fine until i include the civilian header. -
void giveJob(Job &);
-
void advanceTask();
-
Job myJob;
that code works just fine and compiles but as soon as i add:
to the Job class header,
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...
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.
the contens of my civilian header are as follows: - #ifndef Civilian_h
-
#define Civilian_h
-
#include <iostream>
-
#include <string>
-
#include "Job.h"
-
using namespace std;
-
class Civilian
-
{
-
public:
-
static long nextID;
-
//-------------------------
-
//--constructors-----------
-
Civilian();
-
Civilian(int);
-
//-------------------------
-
//--public member variables
-
long myID;
-
bool isAlive, hasJob, hasHouse;
-
int daysWithoutFood;
-
string pronoun;
-
//------------------------------------
-
//--methods involved in daily activity
-
void age(int);
-
bool eat(int,int);
-
void advanceDay();
-
void satisfy(int);
-
//--------------------------------
-
//--methods involved in working
-
void giveJob(Job &);
-
void advanceTask();
-
Job myJob;
-
//--------------------------------
-
//--methods to access private members
-
const string getName(){return name;}
-
const string getCivString();
-
const int getSatisfaction(){return satisfaction;}
-
private:
-
//--identification
-
void assignName();
-
string name;
-
char gender;
-
int ageDays,ageMonths,ageYears;
-
//--statistical
-
long totalFoodConsumed;
-
//--pertinant to other calculations
-
int satisfaction;
-
public:
-
static string itos(int);
-
string getAgeMDY();
-
string getIsEmp();
-
};
-
#endif
-
I compiled OK using your Civilian.h and this main() with Visual Studio.NET 2005: -
int main()
-
{
-
bool hasWorker;
-
void assignWorker(Civilian *);
-
Civilian *myWorker;
-
-
}
-
All I had to do was create an empty class Job.
I did get a warning here: -
const int getSatisfaction(){return satisfaction;}
-
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.
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....
Maybe it's time to look at your Job.h.
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...
Post it. I'm curious now.
I intend to compile your code using Visual Studiuo.NET 2005.
-
#ifndef Job_h
-
#define Job_h
-
-
#include <iostream>
-
#include <string>
-
#include <vector>
-
#include "Civilian.h"
-
using namespace std;
-
using std::vector;
-
-
class Job
-
{
-
public:
-
Job(string, int);
-
Job();
-
void accomplishTime();
-
string getName();
-
string getActiveTask();
-
bool hasWorker;
-
Civilian *myWorker;
-
private:
-
void analyzeDataFile();
-
int destination, pos, taskCount;
-
vector<int> taskTimes;
-
vector<string> taskNames;
-
int goodsPerCycle, startDelay, taskTimeRemaining;
-
public:
-
int activeTask;
-
string jobName;
-
};
-
#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
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: -
class Civilian; //forward reference
-
class Job{
-
{
-
Civilian* myWorker;
-
};
-
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.
what would that "forward reference" do? how do they work?
that will probably fix the other problems i was having as well
thank you
The rule is: You cannot use a type before you declare it.
Therfore this code: -
class Job
-
{
-
Civilian* myWorker;
-
};
-
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: -
class Civilian; //forward reference
-
class Job
-
{
-
Civilian* myWorker;
-
};
-
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.
ok yea that definitely fixed the problems...thanks alot
Sign in to post your reply or Sign up for a free account.
Similar topics
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 #...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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) {}
};
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |