As far as I know, the extern keyword is used for declaring a global variable which need to be use within several files.Usually the extern keyword is defined in the header file and reuse in many .cpp or header files
Yesterday I saw a special(?) usage in our code bases, the author declare an extern variable in .cpp and define the variable in the main.cpp
d.cpp
extern int whatever; //yes, it is declared in .cpp but not .h
main.cpp
#include "d.hpp"
int whatever = 100;
int main()
{
//do something
}
What are the benefits and drawbacks of declaring an extern variable in .cpp but not .h?Never hear a technique like this before and can't find an example by google.