📜 ⬆️ ⬇️

This mysterious C ++ (std :: min and static const int)

Suddenly, it turned out that g ++ does not compile (or rather does not link) the following code (it works in 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 .


with a diagnosis of:
 Fail.cpp :(. Text + 0x15): undefined reference to `Test :: a '
 ...

')
If we assign values ​​to constants outside the class (const int Test :: a = 0), then everything works.

Source: https://habr.com/ru/post/73623/


All Articles