0

I am writing a simple program that uses an object *center from an XYPoint class as an instance variable.

@interface Circle : NSObject {
    int radius;
    XYPoint *center;
}

however, I get this error message when compiling the code:

error: expected specifier-qualifier-list before 'XYPoint'

how can I fix this?

2 Answers 2

3

In Circle.h, you need to declare the XYPoint class:

@class XYPoint;

Then, in Circle.m, import its full definition:

#import "XYPoint.h"
Sign up to request clarification or add additional context in comments.

Comments

1

You need to include the appropriate header file that defines the XYPoint class.

2 Comments

I disagree. Importing the XYPoint.h into Circle.h introduces an unnecessary dependency that will slow down build time. Better to declare it with @class, and put the #import in Circle.m.
@Sherm Pendley Indeed, @class would be more preferable, I agree.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.