Pull to refresh

Этот загадочный C++ (std::min и static const int)

Reading time1 min
Views2.1K
Внезапно обнаружилось что g++ не компилирует (а точнее не линкует) следующий код (в MS VS 2008 работает)

#include <algorithm>

struct Test
{
  static const int a = 0, b = 1;
};

int main()
{
  std::min(Test::a, Test::b);
  return 0;
}


* This source code was highlighted with Source Code Highlighter.


с диагнозом:
Fail.cpp:(.text+0x15): undefined reference to `Test::a'
...


Если присвоить значения константам вне класса (const int Test::a = 0), то всё работает.
Tags:
Hubs:
Total votes 13: ↑9 and ↓4+5
Comments3

Articles