I have such a structure (for some reason I cant just use an array):
struct OperatorData
{
char m_record_0[RIX_OPERATOR_CONFIG_SIZE];
char m_record_1[RIX_OPERATOR_CONFIG_SIZE];
//....
char m_record_9[RIX_OPERATOR_CONFIG_SIZE];
};
And I am trying to calculate amount of fields at compile-time:
enum {fieldsAmount = sizeof(OperatorData) / sizeof(OperatorData::m_record_0)};
And the compiler reports such a message:
Error: #245: a nonstatic member reference must be relative to a specific object
enum{fieldsAmount = sizeof(OperatorData) / sizeof(OperatorData::m_record_0)};
^
I use keil uVision3 V3.60.
It doesn’t matter where I place enum declaration inside or outside the structure.
Why can’t the compiler take size of this membmer?
It looks like your compiler doesn’t support C++11 that allows the use of
Type::memberin unevaluated expressions. You’ll have to manufacture an expression of the correct type, something like: