1
对于以下的代码:初始化从数据文件中的静态const成员
class A
{
public:
static const int VAL;
};
我知道我可以分配VAL在类声明的值:
class A
{
public:
static const int VAL = 3;
};
或在CPP文件:
const int A::VAL = 3;
但我想从数据文件中读取值。我有一个功能,现在,让我们称之为F(),读出此值,我想:
void F()
{
int value = ReadValueFromDataFile();
//But I can't do this:
const int A::VAL = value; //member cannot be defined in the current scope
}
我如何分配VAL的值根据从数据文件中读取值?
就像在第二个例子中一样,它只适用于整型(非std :: string)。 – 2012-02-28 22:19:19