Reputation: 1421
In a.cpp:
int t()
{
//definition goes here
...
}
b.cpp:
#include "a.h"
int main()
{
t();
}
finally a.h:
extern int t();
//int t();
Both forms of a.h works,why?
Upvotes: 1
Views: 98
Reputation: 64845
Because function are extern by default, so the extern keyword is redundant. Some people like to explicitly add the extern when they want to hint other developers that the definition of the function are not to be found in the .cpp file with same name than this .h file, then they add a comment to point where the function is declared. But to the compiler's perspective, it does not affect anything.
Upvotes: 9