Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Header import paradox

Header import paradox
Thread Tools
Gametes
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Aug 23, 2006, 07:51 PM
 
So I have a class which imports another class. The other class imports the first class. It's impossible to compile. How do you configure the compiler to accept that a class will exist, just a little down the line.

Here's the code in brief:

@interface SDMovieView : QTMovieView
{
SDVideoCell *cell;
}

@interface SDVideoCell : NSImageCell
{
SDMovieView *movieView;
}

Long story short, If I change the classes of the objects, it imports fine. If I change the order for the compiler, the error switches so that it's always in the first file, before the second one comes in. There is nothing wrong with the code. Just the compiler.

I don't understand why I can't have a Control know about it's cell and viceversa.
you are not your signature
     
smitty825
Forum Regular
Join Date: Sep 2003
Location: San Diego
Status: Offline
Reply With Quote
Aug 23, 2006, 08:03 PM
 
This is a common problem in programming. You'll need to tell the compiler that you're going to define the second class later. In Obj-C you can use the "@class" specifer...

In you example, this should work:

@class SDVideoCell;
@interface SDMovieView : QTMovieView
{
SDVideoCell *cell;
}

@interface SDVideoCell : NSImageCell
{
SDMovieView *movieView;
}

Note: There are many times where having a circular dependancy like the above may be hinting at a bad design. I'm not sure if this is the case or not, but it's always wise to double check...
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Aug 23, 2006, 08:04 PM
 
Check out the @class declaration.

EDIT: Beaten to the punch by Smitty!
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Gametes  (op)
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Aug 24, 2006, 10:38 AM
 
Thanks guys, and this when just for the first time I started poking around in the Cocoa header files and I was asking myself "Why the heck does NSCell's @class say:

@class NSAttributedString, NSEvent, NSFont, NSFormatter, NSImage, NSMenu, NSText, NSView;

and I guess that totally explains it.

...Yep: that fixes the problem!
you are not your signature
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:55 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,