Nested Enum Error
Nested Enum Error
- Subject: Nested Enum Error
- From: "K. Darcy Otto" <email@hidden>
- Date: Thu, 20 Mar 2008 20:31:43 -0700
I've been trying to add some human-readable error codes to my classes
using enum, but have been running into some difficulties when I add a
different enum of the same name to a different class. Here is what I
have so far in my DeductionLine class (and I think it will suffice
just to show the interface:
@interface DeductionLine : NSObject {
Dependency *dependency;
LineNumber *lineNumber;
Formula *formula;
Justification *justification;
BOOL wfdl; // well-formed deduction line
enum Error
{
noError = 0, // everything ok
dependencyExistError = 1, // dependency does not exist
lineNumberExistError = 2, // line number does not exist
formulaFormError = 3, // formula is not a wff
justificationFormError = 4, // justification is not a wfj
justificationReferenceError = 5, // justification references lines
greater or equal to lineNumber
justificationMatchError = 6 // justification is $I, but main
connective of formula does not correspond to $
} errorCode;
}
Now, I know the =0, =1 is redundant, but I want it there for ease of
reading, just in case the programmer wants to output errorCode to a
log (which will result in an integer, which can then be looked up in
the interface). This works fine in this class: I can write:
"errorCode = noError;" or whatever, and everything is happy. But when
I try to do something similar in the DeductionLineSequent class, there
is no end to compiler complaining:
@interface DeductionLineSequent : NSObject {
NSArray *sequent;
NSArray *additionalFormulae;
BOOL valid;
enum Error
{
noError = 0, // everything ok
dependencyError = 1, // dependency sequent invalid
lineNumberError = 2, // line number sequent invalid
formulaError = 3, // formula sequent invalid
} errorCode;
}
I get "nested redefinition of 'enum Error'", (ii) "redeclaration of
'enum Error'" and (iii) redeclaration of enumerator 'noError'. So, I
have two questions: is it possible to get each enum local to the class
in which it is defined (so it does not seem to be "nested")? Second,
is there a better strategy for defining human-readable error codes?
Thanks.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden