Consider the following a.cpp and b.cpp files:
ebra@him:/tmp$ cat a.cpp
const int i = 5;
ebra@him:/tmp$ cat b.cpp
int main()
{
extern int i;
return i;
}
ebra@him:/tmp$ g++ *.cpp
/tmp/ccqBWi4e.o: In function `main':
b.cpp:(.text+0x6): undefined reference to `i'
collect2: error: ld returned 1 exit status
The question is how I can use the i variable that is declared in a.cpp file inside b.cpp?
Note that
- I added the keyword
constinsideb.cpptoo, but nothing changed. - I have the same problem with
staticandstatic constvariables too!