Cocoa Import Controllers Model, Import Models Controller & # 8594; An exception

Why isn't it possible in Cocoa for two classes to import each other? I tried the following code:

controller.h:

#import <Cocoa/Cocoa.h>
#import "Model.h"

@interface Controller : NSObject {
 Model *model;
}

@end

      

model.h:

#import <Cocoa/Cocoa.h>
#import "Controller.h"

@interface Model : NSObject {
 Controller *controller;
}

@end

      

which throws the following exceptions:

error: expected specifier-qualifier-list before 'Controller'
error: expected specifier-qualifier-list before 'Model'

      

Can someone explain why this is?

Thanks! xonic

+2


a source to share


2 answers


Explain why? No.

But the solution is to use @class declaration like this:



@class Model;
@interface Controller : NSObject {
 Model *model;
}
@end

      

0


a source


The solution for this is that: Model.h:

#import <Cocoa/Cocoa.h>
#import "Controller.h"

@class Controller;
@interface Model : NSObject {
 Controller *controller;
}

@end

      



And you are done with that

0


a source







All Articles