I believe page 162 has a fairly significant error… the book implies that a non-BNREmployee (such as a BNRPerson) would no longer be able to access the officeAlarmCode… but then the example creates an instance of a BNREmployee. I think they meant to create an instance of a BNRPerson. When I run the code suggested, I do not get the “No visible @interface …” I get “Unused variable” meaning I could very well access the alarm code with the example as stated. Makes sense… a BNREmployee where the class extension exists WOULD be able to use the class extension, whereas a BNRPerson would not.
I think I see the confusion. Are we talking about this snippet?
BNREmployee *mikey = [[BNREmployee alloc] init]; unsigned int mikeysCode = mikey.officeAlarmCode;
The prose just above this snippet is indeed confusing, because it says “objects that are not instances of
BNREmployee…” where it should have said “code that is not running inside of a
The snippet above is presumed to be running in the belly of some other object, or given where we are in the book, just in
main.m. If you type in the above code anywhere other than the .m file of
BNREmployee or a class that subclasses
BNREmployee, you should get the described error. The snippet is correct, but the description around it is in definite need of clarification.
oh I see… and you do mention that it’s the object trying to access the AlarmCode. Coming from C I am still a little fuzzy on the distinction between an object and an instance of an object… and also I most often see the creation of instances in main() so I just assumed this was in main(), not within some other class. Thanks for clearing that up. BTW, really enjoying this book, and so happy this forum exists.