jeudi 23 juin 2016

Undefined reference to static const class member while using std::min on GCC 4.8.4 [duplicate]

This question already has an answer here:

When I try to compile following code (using g++ 4.8.4 with -std=c++11) :

#include <algorithm>

class A
{
    public:
        static const unsigned a = 1;
        //static const unsigned a;
};

// const unsigned A::a = 1;

int main()
{
    unsigned b = 2;
    std::min(/*(unsigned)*/A::a, b);
}

I've got linking error:

undefined reference to A::a

If I define A::a outside of class A or cast A::a to unsigned while executing std::min problem does not exist.

Is it GCC bug? If not what's the root cause of such behavior?

Aucun commentaire:

Enregistrer un commentaire