c++ - Undefined reference std::pair -


one think simple piece of code should compile easily:

#include <utility>  struct q {     static const int x = 0; };  int main() {     std::pair<int, int>(q::x, 0);     return 0; } 

however, when compile g++ using default settings (cygwin gcc 4.5.3) throws linker error @ me:

undefined reference `q::x' 

i'm totally stumped here -- msvc compiles fine yet gcc not. (mingw works fine.)

the linker fails find definition of q::x.

this because std::pair<> constructor takes arguments references const, , q::x l-value, hence requires external definition of q::x able refer that.

a portable fix:

int const q::x; 

Comments