问题
I get this error in a C header file in this line :
char * getFechaHora(time_t & tiempoPuro);
In a C source code file i am including the header file and giving the function an implementation
char * getFechaHora(time_t &tiempoPuro){...}
also in my header file i am including correctly the "time.h" library.
回答1:
In C, if char * getFechaHora, this is your function and the two (time_t & tiempoPuro) are arguments you should declare the function as:
char * getFechaHora(*type* time_t, *type* tiempoPuro);
else if the second is a variable, declare as
char * getFechaHora(time_t *tiempoPuro);
回答2:
char * getFechaHora(time_t & tiempoPuro);
This is not C. C has no reference (&
).
回答3:
The problem is your use of the &
symbol. Passing by reference in that way is not supported in C. To accomplish this in C, you need to pass in a pointer to the variable like so:
char * getFechaHora(time_t * tiempoPuro);
Technically, you are still passing by value (passing the value of the pointer), but it will accomplish the same thing (modifying the value pointed to by the tiempoPuro
variable local to the getFechaHora
function will change the value of the variable local to the function it was called from).
Reference: Pass by Reference
来源:https://stackoverflow.com/questions/12904091/error-expected-or-before-token