swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] strange things with interface files


From: Scott Christley
Subject: Re: [Swarm-Support] strange things with interface files
Date: Thu, 25 Mar 2004 09:14:21 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030922

Paul,

This is often due to circular references with header files. For example, CARunner.m includes in CARunner.h which includes CellSurface.h which includes ModelSwarm.h which finally includes Shrimp.h. Now notice that Shrimp.h performs an include of CARunner.h, but the compiler recognizes that header file was included previously (earlier in the chain) so it skips past it and continues to the @interface Shrimp line.

Now the problem arises in that even though CARunner.h has been included, it has not reached the line in that file where CARunner is defined; i.e. the @interface line. So when the compiler sees the @interface Shrimp, it doesn't yet know anything about the CARunner class and thus the error.

There are two ways to fix this; one is to rearrange the inclusion of your headers to eliminated this circular reference. However, sometimes that is not always possible, so Objective-C provides a class declaration command:

@class CARunner;

which will let you tell the compiler that CARunner is an Objective-C class even though you haven't gotten to the @interface yet.

cheers
Scott

Paul Box wrote:

Hello Group

I have found a couple of threads in the archive describing this problem, but none that seem to give a solution.

I have a program that's been running fine, but has recently started showing errors listed below on compilation. This seems to be a fairly simple Objective-C issue, but I have been staring at the relevant files for a couple of days and am stumped as to what's causing the problem. Any suggestions would be welcome.

Here's what I believe are the relevant files:

---------------------------------------------------
console output
---------------------------------------------------

address@hidden 190304]$ make
gcc -c -g -O2 -g -march=i386 -mcpu=i686 -fgnu-runtime -fno-strict-aliasing -Wall -Wno-import -Wno-protocol -Wno-long-long -Wno-error -D_GNU_SOURCE -DAPPNAME=biox -I/usr/include/swarm CARunner.m
In file included from ModelSwarm.h:15,
                 from CellSurface.h:15,
                 from CARunner.h:69,
                 from CARunner.m:19:
Shrimp.h:22: cannot find interface declaration for `CARunner', superclass of `Shrimp'
make: *** [CARunner.o] Error 1

The files mentioned are:
---------------------------------------------------
Shrimp.h
---------------------------------------------------

#import "CARunner.h"

@interface Shrimp: CARunner
{
  id modelSwarm;
  id cellSurface;
  Color myColor;
  id limboList;

  int size;  // size of the shrimp
  int age; // how old is this shrimp?
}

 ....
@end

---------------------------------------------------
CARunner.h
---------------------------------------------------

#import <objectbase.h>
#import <objectbase/SwarmObject.h>
#import "CellSurface.h"
// #import "neighbor.h"
#import "Eneighbor.h"

@interface CARunner: SwarmObject
{
  id world;
  BOOL embedded;   // if YES, then agent is currently embedded in world;
                   // if NO, agent is currently warped to
                   // "hyperspace"...
  id myCell;  // what cell am I occupying?
  int x, y;
  Eneighbor * eNeighbor;
}
 ...
@end


////////////////////////////////////////
// Paul Box
// Aquatic, Watershed, and Earth Resources
// Utah State University

_______________________________________________
Support mailing list
address@hidden
http://www.swarm.org/mailman/listinfo/support





reply via email to

[Prev in Thread] Current Thread [Next in Thread]