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