简体   繁体   中英

Valid Objective-C method is invalid in Objective-C++?

I've just changed an ObjC file to ObjC++ by changing the extension from .m to .mm . Now, one of my methods gives the error: Expected expression

The following code is an example that works fine in ObjC but NOT in ObjC++ :

- (float)sum:(float)a and:(float)b
{
    return a+b;
}

- (void)run
{
    float s = [self sum:1.5f and:2.5f]; // ERROR HERE
    NSLog(@"Sum = %.1f", s);
}

The only thing I've changed is the file extension. Any idea what's going on and how to fix it? Thanks!

and is a reserved word in C/C++...

(See comments under question)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM