![]() |
|
#1
|
||||
|
||||
error: parse error before `&' tokencard.h:35: error: parse error before `&' token
....what does this error mean?? All I have on line 35 is: CPP / C++ / C Code:
and since it made this error...i just put // in front of line 35 and in my card.cpp file (where i show the actual code for this cardString) i've written the code for this function Then once I go to compile and link these files to run it...i seem to be able to use this function...which shouldn't happen because I commented out the prototype for it. so now i'm really baffled...any ideas? (and as a note...i have: CPP / C++ / C Code:
|
||||
|
#2
|
||||
|
||||
Re: error: parse error before `&' tokenhi..
the problem here is in Card&. i think that & should not come in function prototype... you may use & while invoking function. not for function declaration... |
|
#3
|
|||
|
|||
Re: error: parse error before `&' tokenQuote:
Think about it: Help might be more meaningful if I know: 1. Is this C or C++? I assume C++, but I shouldn't have to guess. 2. Where do you define the function? Where do you call the function? 3. What compiler? In general, if a function is used (invoked) in a file before it it defined (that is, the code for calling function appears before the code for the called function) a prototype is required so that the compiler can know the nature of the function. If a function is defined before the function is called (that is, the function definition --- the code itself --- appears in a file before the function is called) the function prototype is not required. It's OK to have a prototype, if you want to put one in, but the prototype must show exactly the same type and the same number of arguments and their types as the function definition. If your file contains the following code, the compiler will give an error CPP / C++ / C Code:
Two ways to fix it 1. define the function before it is used (put the function's code first) CPP / C++ / C Code:
2. Put a prototype of the function somewhere before it is called: CPP / C++ / C Code:
Regards, Dave |
|
#4
|
||||
|
||||
Re: error: parse error before `&' tokenParamesh: I checked up in my books/notes and to pass it by reference, It says I'm supposed to include the & in the function prototype.
And Dave...sorry bout not including some key info 1) yes it's in c++ 2) okay I prototype in a card.h header file...i define the function in a card.cpp file (with #include "card.h" at the top)...and I actually use the function in another file (say testing.cpp)...I can't remember offhand what I included in that file but I'm not sure why this function (out of like 6) is the only one causing an error. It must have something to do with it being a string returning function because when I change it to a void function, it asks for the prototype but when i use string again, it says that parse error. So I'm not sure what's wrong...I might just delete the code and try starting it over. All my other functions are void and bool and they work perfectly for me. and 3) i use the g++ compiler...i actually compile like g++ -c -Wall -pedantic cards.cpp g++ -c -Wall -pedantic testing.cpp g++ cards.o testing.o -o program (i still don't really know what -Wall and -pedantic does but i'm required to compile as such) I don't have any time this morning to check my testing.cpp file and re-do my function but I'll get back to ya later this afternoon. |
|
#5
|
|||
|
|||
Re: error: parse error before `&' tokenQuote:
Quote:
These command line switches are used to make the compiler print out warnings that are not actually fatal compiler errors, but may indicate something that you need to fix. The default compiler settings (if you don't use -Wall and -pedantic) make the compiler somewhat less verbose. I think it's a good idea to make the compiler tell you every little thing that it can about your code. Regards, Dave |
|
#6
|
|||
|
|||
Re: error: parse error before `&' tokenQuote:
That's why he has to tell us more. If it is C++, then a function argument can be a reference. (So the ampersand is used in the function prototype and definition but not when it's called.) CPP / C++ / C Code:
In C, of course, there is no "call by reference", but you can use the pointer method to allow changes inside the function to affect values of variables in the calling function. Regards, Dave P.S. The error message reported by the Original Poster is, indeed, what I would expect from a C compiler if he used the call-by-reference. Perhaps one of his files was named "something.c" and the compiler, therefore, thought it was a C program. So your comment is consistent with this case. Commonly available compilers for PCs by default treat files named "something.c" as C language, and files named "something.cpp" as C++ files. |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help with enums and function program | rho | C++ Forum | 8 | 27-Jun-2005 19:13 |
| Replacing N'th token in a file. | kobi_hikri | C Programming Language | 2 | 24-Jun-2005 02:00 |
| storing a token pointer as a string | CoreLEx | C Programming Language | 1 | 07-Oct-2003 11:33 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The