tags:

views:

81

answers:

2

What would be the value of Field.Format("%04d", ErrorCode) in the procedure below if the AErrorCode is ERR_NO_HEADER_RECORD_FOUND_ON_FILE?

Somewhere in a .h file:

enum AErrorCode
{
    ERR_UNKNOWN_RECORD_TYPE_CODE = 5001,
    ERR_NO_HEADER_RECORD_FOUND_ON_FILE,
    ERR_DUPLICATE_HEADER_RECORD_FOUND,

    ERR_THIRD_PARTY_LETTER_RECORD_HAS_A_ZERO_REFERRAL_AMOUNT = 5101, 

    ERR_CALL_OCA_UNKNOWN_PROBLEM = 5999
};

In some procedure:

void TADataset::SetErrorStatus(AErrorCode ErrorCode)
{
    NDataString Field;
    Field.Format("%04d", ErrorCode);
    AckRecord.SetField("oca_error_stat", "E");
    AckRecord.SetField("error_cd", Field);
}
+4  A: 
 ERR_NO_HEADER_RECORD_FOUND_ON_FILE == 5002


If you don't specify any value at all, it starts at 0 and increments the next element in the enum. If you specify a value, then it starts incrementing starting by the next element. Unless you reset the counter again by specifying another value for a successor element.

AraK
How? Does it increment?
It increments using whatever was previously defined + 1.
Ralph
starts with 0, increments of 1, unless you specify the next value, then continue incrementing
Amro
Thanks both of you a lot. :)
+2  A: 

According C++ Standard 7.2/1:

<...>If the first enumerator has no initializer, the value of the corresponding constant is zero. An enumerator-definition without an initializer gives the enumerator the value obtained by increasing the value of the previous enumerator by one.

It means that ERR_NO_HEADER_RECORD_FOUND_ON_FILE equal to ERR_UNKNOWN_RECORD_TYPE_CODE+1.

Kirill V. Lyadvinsky