Function of the extern keyword
1. Declare external variables or functions
When the variables or functions you need are in another file, in addition to include, you can also use extern to declare external variables or functions.
// File1.cpp
Int;
Int fun (int w)
{
Return ++ w;
}
// Main. cpp
# Include <iostream>
Using namespace std;
Int main ()
{
Extern int a; // declare an external variable
Extern int fun (int w); // declare an external Function
A = 5;
Cout <a <endl; // 5
Cout <fun (a) <endl; // 6
Return 0;
}
Note that the extern keyword only serves to declare and does not allocate memory space. The declared format must be strictly consistent with the defined format. Www.2cto.com
2. the extern "C" link is specified as the C function library.
Parameter Overloading is a new feature of C ++, which is not available in C. When writing code using C ++, if an error occurs when calling the C function (for the cause of the error, see the implementation mechanism of C ++ overload ), you need to declare the extern "C" to specify the link as the C function library.
Extern "C"
{
/**/
}
From C Xiaojia