// File: InitFirst.h
#pragma once
template <int val>
struct InitFirst
{
static float s_dividedByThree;
};
template <int val>
float InitFirst<val>::s_dividedByThree = val / 3.0;
// File: Test.h
#include <conio.h>
#include <tchar.h>
#include "InitFirst.h"
float g_shouldBeOneThird = InitFirst<1>::s_dividedByThree;
int _tmain(int argc, _TCHAR* argv[])
{
_cprintf("%f\n", g_shouldBeOneThird);
getch();
return 0;
}
g_shouldBeOneThird是否保证初始化为约0.333?换句话说,静态初始化的InitFirst<1>::s_dividedByThree是否保证在用于静态初始化g_shouldBeOneThird时已被初始化?