Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C++, class scope constants, name conflicts




On Feb 9, 2006, at 5:23 PM, Scott Ribe wrote:

What I need is essentially a constant integer value with class scope. In C++
I got used to the class enum trick, but I don't know what to do in an
Objective-C class.


I tried "static const int controlSetCnt = 0;" inside the @interface, but
this causes the compiler to crash. So I moved it outside the @interface, and
it appeared to work fine. However, as soon as I have another class with the
same need and use the same technique, I get "error: redefinition of 'const
int controlSetCnt'". This is because there is one implementation file (my
application delegate) that has to know enough about both these classes to
instantiate them. The constant needs to be in the header file, because it
defines the size of an array member of the class:


 BloodPressure_ControlGroup * bpControls[controlSetCnt];

So my question is: do I really have to avoid this kind of name conflict by
naming a simple constant, which is only used in one class, and not exported
to the linker, with an awful name like:
controlSetCountForClinicExamWindowController


Well, amusingly enough, there is actually an appropriate C++ namespace for
each, so my other option is foo::bar::controlSetCnt...

Perhaps something on this page may help:

<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ Articles/chapter_4_section_10.html>

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Objective-C++, class scope constants, name conflicts (From: Scott Ribe <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.