0

I run into an interesting issue. In my file A.cpp I have a definition

const int I = 1;

in my file B.cpp I declare

extern const int I;

and when I use it, I receive the error message when compiling

'undefined reference to I'

If I remove const in file A, no message and compiles fine. Till now I guessed that const int and int have different signatures. What is going on here what I do not understand?

katang
  • 2,474
  • 5
  • 24
  • 48

1 Answers1

1

You need to have the extern qualifier available when defining a const variable. Otherwise it is used like a compile time constant. And only in the file being compiled.

R Sahu
  • 204,454
  • 14
  • 159
  • 270