Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22040

Objective-C #import loop

$
0
0

I have the following code:

#import <Foundation/Foundation.h>#import "ServerRequest.h" // works even though this line is included#import "ServerResponseRecord.h"@protocol ServerRequestDelegate<NSObject>-(void)request:(id)request gotResponseRecord:(ServerResponseRecord*)response;-(void)request:(id)request gotError:(NSError*)error;@end

It compiles and runs fine. However, if I replace the method declarations with:

-(void)request:(ServerRequest*)request gotResponseRecord:(ServerResponseRecord*)response;-(void)request:(ServerRequest*)request gotError:(NSError*)error;

I get the unexpected syntax error "error: expected ')' before 'ServerRequest'". The only reason I can think this might be a problem is that ServerRequestDelegate.h and ServerRequest.h #import each other. However, I don't understand why the code works with the #import line with (id)request. I also don't understand why it's a syntax error.

Can someone provide a good explanation?


Viewing all articles
Browse latest Browse all 22040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>