swarm-support
[Top][All Lists]
Advanced

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

Can a Swarm instance be treated like a SwarmObject instance?


From: William S. Shu
Subject: Can a Swarm instance be treated like a SwarmObject instance?
Date: Thu, 22 Apr 1999 17:17:30 +0100

Please for assistance.
I defined the following classes, which eventually inherit from SwarmObject:
        @interface SmlObject: SwarmObject { ... }  ... @end

        @interface Population: SmlObject { ... } ... @end

and a model swarm:
        @interface PersonMS: Swarm { ... } ... @end

which inherits from Swarm.

I need corresponding codes, but which inherit from Swarm, since I wanted my
model Swarms to share a similar structure as my swarm objects.  I duplicated
the code (to circumvent multiple inheritance) and obtained corresponding
classes (inheriting through Swarm) as follows:

        @interface SmlSwarm: Swarm { ... }  ... @end

        @interface SmlPopSwarm: SmlSwarm { ... } ... @end

        @interface PersonMS: SmlPopSwarm { ... } ... @end

The ellipses in corresponding classes of the 'Swarm' and 'SwarmObject'
inheritance structure hold the same code.

The trouble, on compilation is that my SmlSwarm class generates the error
messages given further below, while SmlObject compiles well!  Essentially,
it objects to my accessing instance variables via pointers in the
createBegin method below.

My questions then are the following:
1)    Can a Swarm instance be treated like a swarm object, if somehow, one
manages to get it to adopt the Create and Drop protocols?  It seems the only
difference (at interface level) between 'Swarm'  and 'SwarmObject' is the
Create and Drop protocols that 'SwarmObject' adopts.

2)    Can one still treat it as a 'SwarmObject' if one successfully avoids
sending it any messages that require the Create and Drop protocols?

3)    Why does swarm compilation objects to pointer access under 'Swarm' but
not under 'SwarmObject'.  It seems to suggest that swarm instance variables
are protected from the 'Swarm' object itself!

4)  I would have expected compilation to complain about createBegin: or all
the other methods I did not provide under the Create and Drop protocols, but
it didn't.  Why?

5) After commenting out the offending code fragment, my program seems to run
with no visible problem, yet.  Am I safe now in using 'Swarm' objects in
ways similar to 'SwarmObject' objects or am I sitting on a time bomb?


The code and error messages follow:

The createBegin Method:

+ createBegin: aZone
{
  SmlObject *obj;

  obj = [super createBegin: aZone];

  // initialise SmlObject to suitable (harmless) defaults
  obj->birthday = 0;
  obj->position.x = 0;

...

  return obj;  // return self
}



Compilation messages:

cd c:/u/mosq/proto/
make -k SmlSwarm.o
gcc -c -Wno-import -g -O2 -fno-inline  -I/Apps/Swarm-1.3.1/packages/swarm/in
clude SmlSwarm.m
SmlSwarm.m: In function `_c_SmlSwarm__createBegin_':
SmlSwarm.m:317: instance variable `birthday' is declared protected
SmlSwarm.m:318: instance variable `position' is declared protected
SmlSwarm.m:319: instance variable `position' is declared protected
SmlSwarm.m:320: instance variable `clusterList' is declared private
SmlSwarm.m:321: instance variable `world' is declared protected
SmlSwarm.m:322: instance variable `valueSpace' is declared protected
SmlSwarm.m:323: instance variable `modelSwarm' is declared protected
SmlSwarm.m:324: instance variable `smlColor' is declared protected
make: *** [SmlSwarm.o] Error 1
gcc -c -Wno-import -g -O2 -fno-inline  -I/Apps/Swarm-1.3.1/packages/swarm/in
clude SmlPopSwarm.m

Compilation exited abnormally with code 2 at Thu Apr 22 16:32:27


Thanks

William.



                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

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