For the following code:
class A
{
public:
static const int VAL;
};
I know that I can assign VAL a value in the class declaration:
class A
{
public:
static const int VAL = 3;
};
or in the CPP file:
const int A::VAL = 3;
But I would like to read the value in from a data file. I have a function now, let’s call it F() which reads in the value I want:
void F()
{
int value = ReadValueFromDataFile();
//But I can't do this:
const int A::VAL = value; //member cannot be defined in the current scope
}
How can I assign the value of VAL based on a value read in from a data file?
At their definition (not their declaration) initialize the variables with the return value of a function call.