unresolved external symbol "int const value"

One file states:

1
2
3
4
extern const int value;
extern const int this_cpp;
const int mine = value;
const int yours = 40;


and another cpp states

1
2
const int value = 12;
const int this_cpp = 33;


Still I get unresolved external symbol "int const value"! Why?


Your other.cpp file also needs to say extern, otherwise it's taken to have internal linkage only.

https://en.cppreference.com/w/cpp/language/cv
The const qualifier used on a declaration of a non-local non-volatile non-template(since C++14)non-inline(since C++17) variable that is not declared extern gives it internal linkage. This is different from C where const file scope variables have external linkage.


Registered users can post here. Sign in or register to post.