![]() |
|
#1
|
|||
|
|||
" 'expected' errors "And lots of 'em. I'm using g++ from MinGW and was able to minimize errors for this little test program, but many "expected some token" errors remain.
In 'chars.h' and 'functions.h' I get them: chars.h: Mostly "expected unqualified-id before '.' token" and "expected ',' or ';' before '.' token" for every line from 42 till 71. functions.h: In void_welcome_screen() all of them "expected primary expression before '.' token" from line 30 to 66, throughout most of them lines. Now, it's been a while since I've seen code, and I just suddenly started trying to make a simple text game, going along as I saw fit, so it might be a stupid little thing I forgot or sum' like that (and I'm just doing this for fun, though you might question why would an inexperienced person be learning/doing C++, heh heh). By looking at the code I couldn't see anymore things that are wrong. Been fooling around with using and #include but no good result yet. Sidenote: seems I can't declare and simultaneously initialize variables inside a struct? Not so likeable. Anyway, can't attach .h files, so here's the code in the post. MAIN.CPP CPP / C++ / C Code:
CHARS.H CPP / C++ / C Code:
FUNCTIONS.H CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
Re: " 'expected' errors "Quote:
That's not the way to use headers. I mean, that's not the way that people "usually" use headers. Regardless of "usual" practice, the way that you wrote them and included them is just flat wrong. To see what the compiler is seeing: paste the stuff from the headers into the main file instead of using #include. What you get is illegal. For example, chars.h has assignment statements. But you include it in at a point in your source file that is not inside a function. Therefore: that does not compute. Regards, Dave "No one was born knowing this stuff, you know." ---davekw7x Last edited by davekw7x : 25-May-2007 at 15:57.
|
|
#3
|
|||
|
|||
Re: " 'expected' errors "Quote:
No matter what I do, though, and "fix", those 'expected primary expressions before '.' token' remain and 'expected unqualified-id' and 'expected ',' ' ETC., remain as well. I put the contents of the .h files into main.cpp, fixed some compiler errors, and basically have the same thing left as before, that about the 'expected' stuff. I've just been at it for a couple hours now, and looking through it any more will probably force me to throw myself out the window and break a neck (maybe mine or somebody else's who breaks my fall, heh heh). I did read somewhere that it "might have to do" with line endings(?) when you copy and paste pieces of code or some stuff like that...? Vague. I did sometimes copy/cut and paste some code I wrote, but would it really matter? I thought a compiler doesn't care about it. ANYWAY, uh... help me |
|
#4
|
|||
|
|||
Re: " 'expected' errors "Like Dave said: you can only assign things inside a function. At any rate, you are assigning values, and attempting to access them later, as if there was only one instance of each struct (with the name of the struct as the variable name), which is a misconception. Also, you have defined five different structs (data types) which are all exactly the same. You definitely need to review declaration, purpse and usage of structs.
|
|
#5
|
|||
|
|||
Re: " 'expected' errors "Quote:
In addtion, i will show a simple example. CPP / C++ / C Code:
CPP / C++ / C Code:
Quote:
Hope this helps!!!!!!!!! One point to take note, which is a good programming practice. Don't de-reference a strucuture field (eg. this->hp). Create a function that return the value would be a better choice. I did that to save some space if not my reply would be lengthy. This applies to setting the value. |
|
#6
|
|||
|
|||
Re: " 'expected' errors "The information you all gave for which I'm thankful is kind of overloading and confusing me
I will have a shot at it, but I don't expect to get it. Now that I think of it, though, wouldn't it be better to use classes instead of structs and such? - From what I understand, ubergeek, you're saying those variables in the structs have the same names (which is not allowed?) and I'm using the names of the structs to distinguish but it's futile? Makes sense. You're right that I should probably have a look at structs use again. (Sometimes I don't know why I'm putting myself through the pain of C++ (and, before that, C) when I can use a higher-level language probably more easily for what I want to do.) |
|
#7
|
|||
|
|||
Re: " 'expected' errors "Quote:
Those things that we present are BASICS of C/C++ programming. I purposely did an example to address what you did wrong in your code. Kindly read the comments. If you don't understand the keywords / reserved words of C/C++, read some books or search the net. I suppose we are here to help if you have diffculites in program and not teach you C/C++ programming. Let me give you an idea of my presented code. CPP / C++ / C Code:
Theese are known as preprocessor directive. #define means to define a certain value or a macro For example #define PI 3.142 tells the comiler that whenever PI is encountered in the program, replace it with 3.142. Note that it is not a variable declaration. #ifndef _GAME_CHAR_H_ #define _GAME_CHAR_H_ From GameChar.h - the above tells the compiler #ifndef _GAME_CHAR_H_---> meaning "if not define" this "_GAME_CHAR_H_", then #define _GAME_CHAR_H_. #endif is added at the end of the file The is done so the file "GameChar.h" is not included multiple times. Anyway you will get an error during compilation if the file is included multiple times. Now to typedef, which means "type definition". For example i can represent days of week (monday, tues, ....etc) as interger of value 1, 2, 3, 4 ..... respectively. But i want more understandable format, thus i created my own enumeration type..... call WEEK_DAYS CPP / C++ / C Code:
To use it, it is same as ur basic type declarations CPP / C++ / C Code:
I even provided 2 different examples of declaring and initializing a structure. As i can see, most of your mistakes are in the structure. The first is quite easy to understand. The second one, i used a function CPP / C++ / C Code:
I would appologise as i did a malloc, but i did not free it at the end of the program. CPP / C++ / C Code:
Hope this gives you a clear picture. Thanks! |
|
#8
|
|||
|
|||
Re: " 'expected' errors "ahbi82, as said I appreciate your efforts and just to be sure I mean no offence
You're right in saying you don't have to teach me basics of the language, its features, but I didn't ask you to either. In that particular context I've only told you I'm unfamiliar with #ifndef, #endif, and typedef (for the simple reason that most sources and explanations I've seen are simply unnecessarily vague, unclear, and trivial, and that simply withholds me from even touching these three for the nth time!). It makes me raise my eyebrows everytime I see them, whether in an example or in a textbook. I'm just critical to everything I see so I'm questioning if there's an easier way than your example. My purpose was to quickly solve those compiler errors (made in the structs and such, about "expected before tokens") and move on continuing making the thing, without losing time having to sweat through a couple of these little annoying critters again (that I've always loathed as much as I loathe it when my landlord comes at the door) as I've lost hours already(!), if it's possible to go for an easier quick solution. I'm still checking your examples. Thanks kindly for your help and effort/time! |
Recent GIDBlog
Toyota - 2008 August Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Converting PHP to C and I need a little help | Allenport | C Programming Language | 4 | 14-Aug-2006 13:38 |
| Compile Errors due to Default Parameters | jdbrine | C++ Forum | 1 | 17-Jun-2006 14:45 |
| getting following errors in vc++ | angel188 | MS Visual C++ / MFC Forum | 4 | 13-Jun-2006 14:10 |
| Compiler errors | vital_101 | C Programming Language | 4 | 12-Jan-2006 13:53 |
| Help with syntax errors | PeteGallo | C Programming Language | 7 | 08-Aug-2005 20:30 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The