![]() |
|
#1
|
||||
|
||||
Can enum have same name as class?After spending several weeks modifying source code from my textbook, I ran into a problem I didn't anticipate. I had given my enum's the same name as the classes they are in. Naturally, I get nasty errors when I compile.
Is there a way to keep all these names the same? (I thought C++ would be more forgiving, but I guess not). If I have to change the names, is there an easy way to do this? (I got lost when I started to do it by hand and ended up w/ more errors). I'm attaching the source so you can understand just how bad I screwed up; I'm aware there are other errors present but I will attack them later. Unless I find out they are all related, then I might give up; I don't want to recode this mess again. (Can you tell I'm getting burnt out after 8 months in one class? __________________
Common Sense v2.0-Striving to make the world a little bit smarter. |
|
#2
|
||||
|
||||
|
Quote:
I'll not try to debug your dilemma. Here's a suggestion: Try to compile each program one at a time and resolve all errors (and at least reconcile yourself to any remaining warnings). For example (if you are using GNU compiler): g++ -c auto_name.cpp This just takes this one file and tells you some things. I got the following, rather helpful hints: Quote:
If you are using some other compiler, try it on each file with the -c option. For example Microsoft VisualC++ from Visual Studio 6 try cl -c auto_name.cpp /GX Quote:
With Microsoft Visual C++ from the Visual C++ 2005 Express beta download try cl -c auto_name.cpp /EHsc Quote:
Maybe you can see some light at the end of the tunnel. Another suggestion (which may or may not be applicable to this case, but is something that I generally do): When creating new code or modifying code, try compiling it after a few lines or a few tens of lines. I don't wait until I have 10,000 lines spread over 34 files and then try to compile it all together. For new programs, a top-down approach says: first create all classes, structs, etc. and see if they are correct (or create them as you recognize their need during the development). Then start at the top (usually main()) and try it. For functions, put in the prototypes, and try to compile (use the -c compiler switch so that you don't actually have to have the function bodies yet.) That's one way; it's certainly not the only way, and I don't claim it's the best way for everybody. It works for me. Your Mileage May Vary. Regards, Dave "We can face our problem. We can arrange such facts as we have with order and method." --- Hercule Poirot in Murder on the Orient Express |
|
#3
|
||||
|
||||
|
The best way to get around this is to create the enums in a namespace.
Example: CPP / C++ / C Code:
__________________
-Aaron |
|
#4
|
||||
|
||||
|
Thanks for the tidbits.
I may not have explained properly, but the source code was taken from the textbooks web site and modified to do what the question asked for. That's probably why I have so many errors; apart from rewriting small bits within each class (read: make new errors I got beaucoup errors, just like in dave's post, so I know there's quite a bit wrong. And please don't think I was asking for someone to debug it; I just didn't know if some of my errors were due to having the same names. Hope that explains this mess. __________________
Common Sense v2.0-Striving to make the world a little bit smarter. |
Recent GIDBlog
Flickr uploads of IA pictures by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Introduction to .NET | LuciWiz | .NET Forum | 5 | 09-Aug-2007 04:53 |
| Error C2146: syntax error : missing ',' before identifier 'C4' | mattchew008 | C++ Forum | 2 | 19-Dec-2004 06:06 |
| Help! Some basal questions about MFC | xutingnjupt | MS Visual C++ / MFC Forum | 1 | 05-Dec-2004 03:38 |
| hashing help | saiz66 | C++ Forum | 1 | 06-Jul-2004 06:16 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The