I am passing a parameter as poineter in my prtotype but in the definition i am passing as reference. i am getting the warning prototype not defined.Why
Hi nabakishorebehera,
please make sure you use [code=cpp]...[/code] tags round your code when you post it.
Well that is because C++ supports function overloading, you have not provided the prototype for the function you have defined (that uses a reference) but you have provided a prototype for a function you have not defined.
The prototype and the definition must be exactly the same with the sole exception that in C++ (not in C) the prototype may provide default values for arguments which must not appear in the definition.
Are you trying to create a function in a CPP file that can be called from C? A fairly common technique.
To do this
- The prototype MUST match the definition
- Where you have the prototype in the header you must mark it as a function that uses the C naming convention, that is that does not perform then name mangling that C++ introduces to facilitate function overloading. The normal method of doing this is to inlude this code in the header file
-
#ifdef __cplusplus
-
extern "C" {
-
#endif
-
-
// Prototypes for functions using C calling convention here
-
-
#ifdef __cplusplus
-
}
-
#endif
-
You will then be able to call the function from C or C++, the function itself may reside in a C or CPP file, if it does reside in a CPP file then even though it has C naming convention you will be able to use C++ in the body of the function, thus allowing C code to make calls into C++ code.