0

I seem to be having a bit of trouble with using classes from other files in my interface. The way I have written it so far is...

#import "NodeBase.h"

@interface Node : NSObject {
@public
     Node * testnode;
}

where NodeBase is a header file that deals with the importing of the other classes i.e.

#import <Foundation/Foundation.h>

#import "Node.h"
#import "NodeConnection.h"
#import "NodeProperty.h"

The error I am getting is a "Parse Issue: Expected a type", is there no way to use a class in this context? Or have I got the syntax completely wrong?

1
  • 1
    A Node which contains a Node. Looks like some kind of circular reference thing going on there in your Node declarations. Commented Dec 25, 2011 at 12:48

2 Answers 2

2

Your NodeBase.h imports Node.h, and your Node.h imports NodeBase.h, creating a circular reference. This is not allowed.

You can put everything in the Node.h

#import <Foundation/Foundation.h>
#import "NodeConnection.h"
#import "NodeProperty.h"

@interface Node : NSObject {
@public
     Node * testnode;
}

Then you can simply import Node.h in places where you need to reference Node*.

If you would like to hide common imports (e.g. <Foundation/Foundation.h>), you can put them into SupportingFile/<Your-Project-Name>.pch file.

Sign up to request clarification or add additional context in comments.

2 Comments

Oh that makes so much sense, I will keep an eye on that in the future, Thank you for the fast reply have a wonderful Christmas :)
Ok i did try this, but I need to import The node class into the other classes, I think i might just need to rethink/ abstract some of these classes, unless there is an alternative.
2

The method I use for eliminating circular dependencies is using the following definitions:

@interface Node;

or

@class myClass;

just adding this line defines the interface or class and makes it known to the compiler. The actual long definition can follow after

So to the point, try adding the line @interface Node; before the beginning for your interface

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.