swarm-support
[Top][All Lists]
Advanced

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

Mistake in subclassing from AppendFile. Where?


From: Paul Johnson
Subject: Mistake in subclassing from AppendFile. Where?
Date: Wed, 22 Jul 1998 10:39:21 -0500 (CDT)

I've made some basic mistake, but after staring at it for hours,
I am asking for one of you to look too.  I have gotten the same job
done in the past just using regular C commands and fprintf and such, but
I wanted to be more SwarmLike!

I am using AppendFile (from simtools)  to write out data values to a file for
use in a graphics package.  I found that the putFloat method (inherited from
OutFile) does not give the format I want, so I want to subclass from it and
rewrite the putFloat method to output 4.2f or something that is more readily
imported into other programs.  So I created a new class, "Outfiler" and added
one new method, putFloat2.  The code compiles but I get a runtime crash
because the object of type AppendFile does not recognize putFloat2.  If
I change the call to putFloat, the program runs fine, but it gives me
those wrong kinds of output again.  

So, obviously, I've missed some step in adding a method.

Here is what I did.

----------------Outfiler.h--------------------------
#import <simtools.h>
#import <simtools/AppendFile.h>

@interface Outfiler: AppendFile {  }

- putFloat2: (float) aFloat;
- sayHi ;

@end

----------------Outfiler.m-------------------------
#import "Outfiler.h"

#include <stdio.h>

@implementation Outfiler

- putFloat2: (float)aFloat
{
  fprintf(theFile, "%+4.2f", aFloat);
  return self;
}

@end
______________________

In ModelSwarm.h, I include #import Outfiler.h and add a variable
 
   Outfiler * logFile;

In ModelSwarm.m, in buildobjects I add this

   logFile= [Outfiler create: [self getZone] withName: "log.file"];

And I created a method like this in ModelSwarm.m:

-logResults { 
    int q, r; 
    [logFile putString: "Run group"];

    for(q=0;q<2;q++){
      [logFile putInt: [[recruiterList atOffset:q] getGrpNumber]];
      [logFile putString: " "];
      
      for(r=0;r<DIMENSION;r++){
       [logFile putInt: q]; [logFile putInt: r];[logFile putString: " "];
       [logFile putFloat2: [[grpOfferingList atOffset:q] getCoordinate: r]];   
      }
      }
}

ModelSwarm calls itself to carry out logResults, and as I said, it
runs fine if I use putFloat, but I get the "does not recognize" crash
with putFloat2.

Oh, yes, I did in Makefile add an object line for Outfiler

Paul E. Johnson                      address@hidden
Dept. of Political Science           http://lark.cc.ukans.edu/~pauljohn
University of Kansas                 Office: (913) 864-9086
Lawrence, Kansas 66045               FAX: (913) 864-5700
 


                  ==================================
   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]