2010-02-08 2 views
5

Sto cercando di dichiarare una routine di callback in C++ come segue:Che cosa significa l'errore "Tipo incompleto non consentito"?

void register_rename (int (*function) (const char *current, const char *new)); 
    /*------------------------------------------------------------*/ 
    /* WHEN: The callback is called once each time a file is received and 
    * accepted. (Renames the temporary file to its permanent name) 
    * WHAT: Renames a file from the given current name to the specified new name. 
    */ 

Tuttavia, ottengo il seguente errore:

line 204: error #70: 
     incomplete type is not allowed 
void register_rename (int (*function) (const char *current, const char *new)); 

Non sono sicuro di come risolvere questo. Ho altre routine di callback simili dichiarate nello stesso file di intestazione e non ottengo questo errore.

Si prega di aiuto! :)

+11

evidenziazione della sintassi fornisce un utile suggerimento qui ... – ephemient

+0

È inoltre possibile trovare questo più facile da codice se si typedef il pointer di funzione: 'typedef int (* fn) (const char *, const char * newStr); void register_rename (fn); ' –

+1

Inoltre,' void register_rename (int (*) (const char *, const char *)); 'è un prototipo equivalente; i nomi non sono necessari. – ephemient

risposta

19

Non è possibile utilizzare nuovo perché è una parola chiave. Prova a scegliere un identificatore valido per il tuo secondo argomento.

7

Non è possibile denominare una variabile (o qualsiasi identificatore) con una parola riservata;

parole riservate sono parole chiave

asm do if return try 
auto double inline short typedef 
bool dynamic_cast int signed typeid 
break else long sizeof typename 
case enum mutable static union 
catch explicit namespace static_assert unsigned 
char export **new** static_cast using 
class extern operator struct virtual 
const false private switch void 
const_cast float protected template volatile 
continue for public this wchar_t 
default friend register throw while 
delete goto reinterpret_cast true 

e alternative nomi di alcuni operatori

and and_eq bitand bitor compl not 
not_eq or or_eq xor xor_eq