![]() |
|
#1
|
|||
|
|||
bool problem in multi file formatHi,
I am using multi files on this assignment with code assigned to be used "as is". Problem is the utility file is giving an error on the bool line in the form of a compile error that says 'bool : redefinition; different basic types' and to look at the definition of bool in Lab2.cpp. I am at a loss to see why this is not working, except that it probably has something to do with 'const'. However, 'const' is a required part of this exercise... Code follows, grateful for any advice you can offer so that I can fix the error(s)... CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
Re: bool problem in multi file formatQuote:
Other than something missing at the beginning of your Utility.h (probably some #ifndef...#define stuff for the inclusion guards), there are a couple of problems that make the assignment quite impossible to complete if you are using a standard C++ compiler. First of all, bool is a reserved key word in standard C++. bool is a built-in data type, and, in the exact words of the C++ standard: bool will be "unconditionally treated as" a keyword. See Footnote. Now, if you comment out that line in Util.h, you are left with an error that the prototype for Queue::empty is different from the implementation definition. One has const and the other doesn't. They must agree. Exactly. Also, standard C++ forbids declaration of 'main' with no type (it has to have an integer data type, usually int). Some compilers allow it as you have shown, but it's not really right. Finally, in my opinion, the file Queue.h requires that Utility.h be included. The fact that you put them in the correct order in your main file makes it work, but I think that it is bad program design. I really, really believe that all files that require inclusion of some other file should #include them explicitly, and not depend on some other program unit including them in the correct order. I understand that you may not be in a position to challenge whoever it was that gave you the stuff with the command to use them "as is," but I thought it worth a comment or two. Bottom line: It won't work on any of the various compilers that I have unless you throw away the bool redefinition and make the empty definition agree with its prototype. Regards, Dave Footnote: Reference International Standard ISO/IEC 14882-2003 Programming languages --- C++ |
|
#3
|
|||
|
|||
Re: bool problem in multi file formatThanks Dave. I don't know if you remember, but you were extremely helpful on an inventory program I had to complete for my class last semester. Thanks again.
I have this class and lab tonight. I am thinking the instructor left something out (or I missed something). I'll see what I can find out and thank you in the meantime for your help. Best regards, Paul |
|
#4
|
|||
|
|||
Re: bool problem in multi file formatAhhh! That was it!! Including utility.h in Queue.h leads to a successful compile! Eureka!!
That #include in Queue.h is fine with respect to the rules of the assignment. I was not entirely clear about that in my first post. The instructor is really picky about having code input exactly as it appears in his assignment. However, there are exceptions. For instance, there are no restrictions on using #include "utility.h". On the other hand, the class and functions must appear "as is." He has a main program too that must appear precisely as he has assigned it. I hope you will bear with me as I may have new questions as I add in the stack class, its functions, and main(). Thank you Dave! You are the best! Paul Fanning |
|
#5
|
|||
|
|||
Re: bool problem in multi file formatI spoke too soon. I had remarked out the bool line in ulility.h which is why it was compiling. I got deeper into the project before I discovered the error. It's the same problem, "redefinition; different basic types" and "syntax error constant". There are also two errors about "missing ; before {" and "missing ; before }" but I believe those will clear up. The only lines currently in use for bool are "bool empty()const" in Queue.h and Queue.cpp. If you have ideas as to how I can solve, please adivse.
|
|
#6
|
|||
|
|||
Re: bool problem in multi file formatQuote:
I have already told you: Quote:
Reserved means that you can't define it to be something else. Period. If you or your instructor was using some really old (pre-Standard) C++ compiler, maybe re-defining bool worked, but it's just wrong, wrong, wrong. Get rid of the enum bool thing and try again. If you still have problems, post whatever it is that you are currently working with. Regards, Dave |
|
#7
|
|||
|
|||
Re: bool problem in multi file formatOk. I noticed that the deliverables for this assignment do not include the utility.h file. So, I'm going to move on without the enum bool line. No sense in banging my head against the wall if it is not required.
Thanks again Dave. |
Recent GIDBlog
Toyota - 2008 July Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Power Calibration Error In Nero Fix (hopefully) | matt3678 | Computer Hardware Forum | 53 | 30-Jun-2008 14:19 |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| need help with a console menu system | BullBuchanan | CPP / C++ Forum | 6 | 20-Aug-2006 14:46 |
| Help with syntax errors | PeteGallo | C Programming Language | 7 | 08-Aug-2005 20:30 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The