Compile error: Inheritance related?

This is a discussion on Compile error: Inheritance related? within the C++ Programming forums, part of the General Programming Boards category; My project was working fine, and all of a sudden i started getting this error: Undefined first referenced symbol in ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    3

    Compile error: Inheritance related?

    My project was working fine, and all of a sudden i started getting this error:

    Undefined first referenced
    symbol in file
    Creature type_info function Grass.o
    Creature type_info node Grass.o
    Creature virtual table world.o

    ld: fatal: Symbol referencing errors. No output written to world
    collect2: ld returned 1 exit status


    World is the excecutable, and Grass IS-A Creature.

    using g++ version 2.95.2

    Any ideas? Thanks.

    Sorry for the really long post.

    Code:
    //
    // World
    //
    // 
    
    #include <ezwin.h>
    #include <assert.h>
    #include <rect.h>
    #include "Creature.h"
    #include "Wanderer.h"
    #include "Grass.h"
    #include "linkedList.h"
    #include "unorderedLinkedList.h"
    using namespace std;
    const double PI = 3.14159265;
    unorderedLinkedList<Wanderer> wanderers;
    linkedListIterator<Wanderer> wit; 
    linkedListIterator<Wanderer> wit2;
    unorderedLinkedList<Grass> grasses;
    linkedListIterator<Grass> git;
    linkedListIterator<Grass> git2; 
    ...
    ........................LOTS OF CODE........................
    ...
    // MoveBox(): Move the box a little bit (gets called by timer)
    //            This will animate the box.
    double growgrass =0;
    int LetThereBeLife() {
        growgrass++;
        Wanderer a;
        bool collided;
        bool grazing;
        for (wit = wanderers.begin(); wit != wanderers.end(); ++wit){
            collided=false;
            grazing=false;
            Wanderer temp = *wit;
            undrawWanderer(temp);
            a=temp.act(0);
            
            for (wit2 = wanderers.begin(); wit2 != wanderers.end(); ++wit2){
                if(*wit2 != a && collided==false)
                    collided = collide(*wit2,a);
            }
            for (git2 = grasses.begin(); git2 != grasses.end(); ++git2){
                if(grazing==false)
                    grazing = collide(*wit,*git2);
            }
            if(grazing){
                temp.act(-1);
            }
            
            if(collided){
                temp.act(2);
            }
            else{ 
                temp.act(1);
            }
            
            drawWanderer(temp);
            wanderers.deleteNode(temp);
            wanderers.insertLast(temp);     
        }
        Grass g;
        collided=false;
        for (git = grasses.begin(); git != grasses.end(); ++git){
            
            Grass temp = *git;
            undrawGrass(temp);
            g=temp.act(0);
            
            for (wit2 = wanderers.begin(); wit2 != wanderers.end(); ++wit2){
                if(collided==false)
                    collided = collide(*wit2,*git);
            }
            if( collided){
               temp.act(2);
            }
            else{ 
                temp.act(1);
            }
            drawGrass(temp);
            
            temp.eat();
            grasses.deleteNode(temp);
            grasses.insertLast(temp); 
            cout<<temp.getScale()<<endl;
        
        }
        
        
     
      return 0;
    }
    Grass.h
    Code:
    #ifndef GRASS
    #define GRASS
    #include <iostream>
    
    using namespace std;
    
    
    
    class Grass : public Creature
    {
    public:
        Grass act(int);
        Grass(double,double,int,int,int,int);
        Grass();
        void setScale(double s);
        void eat();
    private:
        Grass *simulation;
    };
    #endif
    Grass.cpp
    Code:
    #include <iostream>
    #include <cstdlib> 
    #include "Creature.h"
    #include "Grass.h"
    
    using namespace std;
    
    Grass Grass::act(int code){
        
        int x = rand()%20;
        int pm = rand()%2;
        int perc = rand()%100;
        // if(perc>50){
    //         if(perc>25){
    //             cout<<"cont right"<<endl;
    //             pm = 0;
    //         }else{
    //             cout<<"cont left"<<endl;
    //             pm = 1;
    //         }
            
    //     }
       switch(code){
            case 0:
                simulation= new Grass(xLoc,yLoc,orientation,worldx,worldy,ID);
                
                break;
            case 1:
                
                
                break;
            case 2:
                
                if(xSize>.01)
                    xSize=xSize-.01;
                if(ySize>.01)
                    ySize=ySize-.01;
                scale-=.01;
                break;
        }
       return *simulation;
    }
    
    Grass::Grass(double x,double y,int orient,int worldsizex, int worldsizey, int cID){
        yLoc = y;
        xLoc = x;
        walkSpeed=0;
        runSpeed=.01;
        maxAngle=20;
        xSize=.2;
        ySize=.2;
        orientation=orient;
        age=0;
        health=10;
        worldx=worldsizex;
        worldy=worldsizey;
        ID=cID;
    }
    Grass::Grass(){
    }
    void Grass::setScale(double s){
        if(xSize<1.5){
            scale+=s/1000;
            xSize+=s/1000;
            ySize+=s/1000;
        }
        
    }
    
    void Grass::eat(){
        setScale(getXSize()+2);
    }
    Creature.cpp
    Code:
    #include "Creature.h"
    #include <iostream>
    #include <math.h>
    
    using namespace std;
    
    const double PI = 3.14159265;
    
    bool Creature::move(double x,double y){
        lastxLoc=xLoc;
        lastyLoc=yLoc;
        if(x>0 && x<worldx && y>0 && y<worldy){
            xLoc=x;
            yLoc=y;
            return true;
        }else
            return false;
    }
    void Creature::run(int angle){
        oldorientation = orientation;
      
        double xTemp;
        double yTemp;
        if(abs(angle-orientation)<maxAngle){
           
            yTemp=-1*sin(angle*PI/180)*runSpeed+yLoc;
            xTemp=cos(angle*PI/180)*runSpeed+xLoc;
            
            move(xTemp,yTemp);
                orientation = angle;
        }
        
            
        
    }
    void Creature::walk(int angle){
        oldorientation = orientation;
      
        double xTemp;
        double yTemp;
        if(abs(angle-orientation)<maxAngle){
           
            yTemp=-1*sin(angle*PI/180)*walkSpeed+yLoc;
            xTemp=cos(angle*PI/180)*walkSpeed+xLoc;
            
            move(xTemp,yTemp);
                orientation = angle;
        }
        
    }
    void Creature::die(){
        // undraw();
        
    }
    
    double Creature::getYLoc(){
        return yLoc;
    }
    double Creature::getXLoc(){
        return xLoc;
    }
    double Creature::getXSize(){
        return xSize;
    }
    double Creature::getYSize(){
        return ySize;
    }
    double Creature::getHealth(){
        return health;
    }
    int Creature::getID() const{
        return ID;
    }
    Creature::Creature(double x,double y,int orient,int worldsizex, int worldsizey, int cID){
        yLoc = y;
        xLoc = x;
        walkSpeed=2;
        runSpeed=4;
        maxAngle=10;
        xSize=3;
        ySize=3;
        orientation=90;
        age=0;
        health=100;
        worldx=worldsizex;
        worldy=worldsizey;
        ID=cID;
        //draw();
    }
    Creature::Creature(){
    }
        
    
    void Creature::setScale(double newscale){
        scale=newscale;
    }
    double Creature::getScale(){
        return scale;
    }
    
    bool Creature::operator == (const Creature c)const{
        return ID == c.getID();
    }
    bool Creature::operator != (const Creature c)const{
        return ID != c.getID();
    }
    int Creature::getOrientation(){
        return orientation;
    }
    Creature.h
    Code:
    #ifndef CREATURE
    #define CREATURE
    
    #include <iostream>
    #include "linkedList.h"
    #include "unorderedLinkedList.h"
    
    using namespace std;
    
    
    class Creature
    {
    public:
    
        bool operator == (const Creature c) const;
        bool operator != (const Creature c) const;
        bool move(double,double);
        void run(int angle);
        void walk(int angle);
        void die();
        double getYLoc();
        double getXLoc();
        double getXSize();
        double getYSize();
        int getID() const;
        double getHealth();
        int getOrientation();
        Creature(double,double,int,int,int,int);
        Creature();
        void setScale(double scale);
        double getScale();
        virtual void eat();
    
    protected:
        double xLoc;
        double yLoc;
        double walkSpeed;
        double runSpeed;
        int maxAngle;
        double xSize;
        double ySize;
        int orientation;
        int oldorientation;
        int age;
        double health;
        int worldx;
        int worldy;
        double scale;
        int ID;
        double lastxLoc;
        double lastyLoc;
    
    };
    
    #endif
    Last edited by blyrrh; 11-08-2006 at 08:02 PM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    With multi-module code such as this, posting a .zip may be more in your interest -- because even though you took the time and pre-apologized for the long post, you are still missing several files that would allow others to attempt to build your project.

    [edit]This isn't that old Borland stuff, is it?
    Code:
    #include <ezwin.h>
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    3
    yea, ezwin is some ancient graphics api, but we have to use it for this assignment. I would have zipped them but im new to UNIX and don't really know how.

    This is the Makefile though if that helps at all:

    Code:
    .SUFFIXES:
    .SUFFIXES: .cpp $(SUFFIXES)
    CC       = g++
    EZWINDIR = ../../EzWindows
    X11DIR   = /X11.6
    
    CPPFLAGS=-I$(X11DIR)/include -I$(EZWINDIR)/include
    LDFLAGS=-L$(X11DIR)/lib -lX11 -lsocket \
    	-L$(EZWINDIR)/lib -lezwin -lXpm 
    
    OBJS=world.o  Creature.o Grass.o Wanderer.o 
    
    default:
    	make world
    
    world: $(OBJS)
    	$(CC) -o world $(OBJS) $(LDFLAGS) 
    
    .cpp.o:
    	$(CC) $(CPPFLAGS) -c $< 
    
    clean:
    	rm -f *.o *~ world

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,434
    Try to rebuild, instead of build?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by blyrrh
    yea, ezwin is some ancient graphics api, but we have to use it for this assignment. I would have zipped them but im new to UNIX and don't really know how.
    I'm surprised to hear that it's possible to build a Borland EzWin app for Windows using gcc on UNIX.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    3
    Quote Originally Posted by Mario F.
    Try to rebuild, instead of build?
    I dont follow, what do you mean.

    and the full name is ezwindows, so it may be different.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Include Compile Info
    By rkensparc in forum C Programming
    Replies: 1
    Last Post: 08-02-2007, 09:38 AM
  2. C and C++ compile speed
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-02-2007, 01:37 PM
  3. Compile as you type
    By Rocketmagnet in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 12-07-2006, 12:36 PM
  4. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 07:20 AM
  5. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 08:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21