Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7995115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:18:57+00:00 2026-06-04T14:18:57+00:00

In the implementation section for Rectangle when I left out #import XYpoint it still

  • 0

In the implementation section for Rectangle when I left out #import "XYpoint" it still worked the same for me. Is putting #import "XYpoint" good practice or does it affect the program?

#import <Foundation/Foundation.h>

@interface XYPoint : NSObject 
@property int x, y;

-(void) setX: (int) xVar andY: (int) yVar;

@end

#import "XYpoint.h"

@implementation XYPoint
@synthesize x, y;

-(void) setX:(int)xVar andY:(int)yVar {
    x = xVar;
    y = yVar;
}

@end

    #import <Foundation/Foundation.h>

    @class XYPoint;
    @interface Rectangle: NSObject

    -(XYPoint *) origin;
    -(void) setOrigin: (XYPoint *) pt; 
@end

#import "Rectangle.h"
#import "XYpoint.h"

@implementation Rectangle {
    XYPoint *origin;
}

-(void) setOrigin:(XYPoint *)pt {
    origin = pt;
}
-(XYPoint *) origin {
    return origin;
}

@end

#import "XYpoint.h"
#import "Rectangle.h"

int main (int argc, char * argv[]) {
    @autoreleasepool {
        Rectangle *rect = [[Rectangle alloc] init];
        XYPoint *pointy = [[XYPoint alloc] init];

        [pointy setX:5 andY:2];
        rect.origin = pointy;

        NSLog(@"Origin %i %i", rect.origin.x, rect.origin.y);
    }
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:18:59+00:00Added an answer on June 4, 2026 at 2:18 pm

    Your implementation of Rectangle doesn’t use any of the specifics of the XYPoint class. It just treats it as a generic pointer and never messages it or dereferences it. Therefore, the forward declaration (the @class statement in the Rectangle interface file) is sufficient. Importing the header doesn’t make any difference to the compiled program.

    It is quite likely that your Rectangle class will eventually evolve to care about the interface of the XYPoint class. When it does, it will need to import that interface declaration. The compiler will warn you if you neglect to import it.

    That said, there’s little reason not to import it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I hide completely this section with red marked. Any QWidget implementation will
In the unit below I have a variable declared in the IMPLEMENTATION section -
In section 3.6.1.2 of both C++ Standard 1998 and 2003 editions, An implementation shall
I can't find a good clean way to lock a critical section in Django.
I was just going through section 5.3 of Operating Systems: Design and Implementation :
I get the error Error 1(E4) end. or implementation section members (types or methods)
In K&R Section 5.10, in their sample implementation of a grep -like function, there
In the Implementation Overview section of the NSPersistentDocument Core Data Tutorial it says: …
Does anyone know if it is possible to wrap the MS PBKDF2 implementation in
My implementation of Sieve of Atkin either overlooks primes near the limit or composites

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.