Microsoft Visual C++ 2008 SP1 Static const member variable bug

Back to programming

This bug is only present when language extensions are enabled. The response from Microsoft was a bit disappointing:

"Hi: this is By-Design - experience showed that most users considered the declaration + initialization within the class to be a definition and hence they didn't understand why the [sic] needed (in some circumstances) to define the member outside of the class. As you said the compiler handles this correctly with /Za."

test.h:

#ifndef TEST_H
#define TEST_H

class Test
{
public:
    static const int V = 2;
};

#endif

test.cpp:

#include "test.h"

const int Test::V;

main.cpp:

#include "test.h"

int main()
{
    return 0;
}