I believe that the static data member of the class can be a reference type initialized by a global variable as follows:
#include <iostream>
#include <stdio.h>
const unsigned int global =0x1fee;
struct K {
int a;
static const int & iref;
};
const int & K::iref=global;
int main()
{
printf("%d\n",K::iref);
return 0;
}
But in my VC ++ test, it can compile, but throw an exception when it is executed. Is this just a bug with VC ++? Did I do something wrong?
source
share