考虑以下。我有两个导出的常量,如下所示:
// somefile.h
extern const double cMyConstDouble;
extern const double cMyConstDouble2;
和
// somefile.cpp
const double cMyConstDouble = 3.14;
const double cMyConstDouble2 = 2.5*cMyConstDouble;
这些常量现在在其他地方引用以定义两个静态(本地可见)常量:
// someotherfile.cpp
#include "somefile.h"
static const double cAnotherDouble = 1.1*cMyConstDouble;
static const double cAnotherDouble2 = 1.1*cMyConstDouble2;
printf("cAnotherDouble = %g, cAnotherDouble2 = %g\n",
cAnotherDouble, cAnotherDouble2);
产生以下输出:
cAnotherDouble = 3.454, cAnotherDouble2 = 0
为什么第二个双0?我正在使用 .NET 2003 C++ 编译器(13.10.3077)。