Obj-C Classes do not form a namespace like they do in C++.

Both enum Error are in the global scope. That is the source of your problem...

Best regards,

B.J Buchalter

On Mar 20, 2008, at 11:31 PM, K. Darcy Otto wrote:

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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/bj%40mhlabs.com

This email sent to [EMAIL PROTECTED]

B.J. Buchalter
Metric Halo
http://www.mhlabs.com
        


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to