compiler error: Expected ':' before 'T'

Discussion in 'iOS Development' started by oninojudo, Jan 14, 2010.

  1. oninojudo

    oninojudo New Member

    Joined:
    Jan 14, 2010
    Messages:
    4
    Likes Received:
    0
    Device:
    iPod touch
    I'm getting a compiler error, but can't determine the root cause.

    Expected ':' before 'T'
    In file included from (...) StartupView.m
    Expected ':' before 'T' in (...) Location.h

    In Location.h:
    + (char) ALL_OUTPATIENT;

    In Location.m:
    + (char) ALL_OUTPATIENT
    {
    return 'T';
    }

    So far, I only get this error when Location.h is included in that one particular .m file, though it has been included in others. Location is a subclass of NSManagedObject. Four of the seven similar methods in the file get this error, but no errors in similar methods in other files so far. Changing the name of the function gets rid of the error. Some of the erroring functions are referenced, others are not. Some have underscores (which are legal), others do not. The error always references the character being returned (in this case 'T').

    I'm stumped.

    ETA: Interestingly, I see this when I preprocess StartupView.m:

    + (char) UNKNOWN;
    + (char) 'I';
    + (char) 'O';
    + (char) ROUNDING;
    + (char) 'N';
    + (char) 'T';
    + (char) FACILITY;

    The three that aren't erroring look fine, the four that are erroring have their return value substituted for the method name.
  2. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    I wonder you uses character for C as Objective-C method?

    you could uses

    [objc]+ (NSString*) ALL_OUTPATIENT { return @"T"; }[/objc]
  3. oninojudo

    oninojudo New Member

    Joined:
    Jan 14, 2010
    Messages:
    4
    Likes Received:
    0
    Device:
    iPod touch
    I'm not sure what you mean by that.

    The method must return a char; returning NSString* would eliminate much of the usefulness.
  4. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    oh, it is should be like char* then
  5. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    No, char * and char are entirely different. The OP is trying to return a literal char, which is fine, I don't see anything wrong with the code he posted, besides disregard for objc naming conventions.

    The OP will have to show us the rest of his code if he would like us to help him.

    Reminder: Objective-C is fully compatible with C (it is a superset).
  6. oninojudo

    oninojudo New Member

    Joined:
    Jan 14, 2010
    Messages:
    4
    Likes Received:
    0
    Device:
    iPod touch
    No, really, I want to return the primitive char. And it can't be just that, because it works on 3 other methods in this class, plus stacks in other classes.
    ------------------double post merged------------------
    She/her, thanks.
    What would you like to see? I posted the function giving the error. The rest of the class is Not Small, plus inherits from another custom class.
  7. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    Sorry

    Please Register or Log in to view images

    .

    My only guess is that the method name is "colliding" with something else you have declared (especially because you said changing the name fixes the error).

    Though, if all you need to return is a constant (literal in this case) value, you don't need a method, you could really just use the C preprocessor -

    e.g.

    Code:
    #define ALL_OUTPATIENT 'T'
    There is little or no reason to have a method that simply returns a literal value. (Performance-wise, and logically).
  8. oninojudo

    oninojudo New Member

    Joined:
    Jan 14, 2010
    Messages:
    4
    Likes Received:
    0
    Device:
    iPod touch
    The problem with a #define is contextual: we want to be able to say [Location ALL_OUTPATIENT], and we also want to be able to say, for instance, [Facility ALL_OUTPATIENT], and have it be different. We're not really happy with doing it this way, but we're coming from a background where you can have public static const member variables. It makes porting difficult if that facility is completely removed, so we're faking it, not that we're happy about that fact.

    In this case, this function is not colliding, in that the string is in exactly two places - the function declaration and definition. One of the functions that *is* working is a class method of two different classes, but no problem there. Also, according to the wikipedia entry on name mangling in objective C, there should be no collision (it should end up looking like _c_Location_ALL_OUTPATIENT - not sure about how the underscore would translate, but it is supposed to be legal - also, two failing functions have no underscores).
    ------------------double post merged------------------
    Found it - overlapping #defines in another area of the app. Xcode project find doesn't work correctly for me, or I'd've found this days ago.

Share This Page