ios - OC为什么类不写实现,突然报了的编译错误?
伊谢尔伦
伊谢尔伦 2017-04-17 17:21:50
0
3
547

昨天的测试工程,代码来自斯坦福CS193P,一开始一点问题没有。今天试试selector 突然就编译不了了。即使注释的就剩ALLOC的那一行代码。究竟是什么问题啊。
奇怪的是补上实现后,又不报错了。

#import <Foundation/Foundation.h>
@interface Vehicle :NSObject
- (void)move;
@end

//!!!!添加实现后build succeeded!!!!
//@implementation Vehicle
//
//@end

@interface Ship : Vehicle
- (void)shoot;
@end


//@implementation Ship
//- (void)shoot {
//    NSLog(@"Shoot!");
//}
//@end

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        //-------------code 2---------------
        Ship *s = [[Ship alloc] init];
        [s shoot];
        [s move];
        
        //Vehicle *v = shipWithShoot;
        //[v shoot];
        
//        id obj = shipWithShoot; //s is Ship
//        [obj shoot];
        //obj = v;    //v is Vehicle
//        [obj shoot];
        
        //-------------code 4----------link 2
//        if ([obj respondsToSelector:@selector(shoot)]) {
//            [obj shoot];
//        }

//
//        if ([obj isKindOfClass:[NSString class]]) {
//            NSString *str = [(NSString *)obj stringByAppendingString:@"xyzzy"];
//        }
        //-------------code 3---------------
        ...
    }
    
    return 0;
}

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
黄舟

I have never encountered this situation. Personally, I think the possible cause is a problem of repeated compilation. For specific details and solutions, you can refer to this blog to completely solve the _OBJC_CLASS_$_certain file name", referenced from: problem. I hope it can help you

Ty80

Of course, the header file only declares symbols. If there are only symbols but no implementation, it will report that the symbol cannot be found when linking

刘奇

It prompts that it cannot be found. If you add the implementation, there will be no problem. As for the problem, it may be a problem with the compiler.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template