can't compile code

I have my files here:

http://cid-1bd707a1bb687294.skydrive.live.com/browse.aspx/C++?uc=5&nl=1

and I can't compile them...it gives me this error:

/tmp/ccthWPyg.o: In function `Item::~Item()':
Books.cc:(.text._ZN4ItemD2Ev[Item::~Item()]+0x13): undefined reference to `vtable for Item'
/tmp/ccthWPyg.o: In function `Item::Item()':
Books.cc:(.text._ZN4ItemC2Ev[Item::Item()]+0xf): undefined reference to `vtable for Item'
/tmp/ccthWPyg.o:(.rodata._ZTV8Aquarium[vtable for Aquarium]+0x28): undefined reference to `Item::print() const'
/tmp/ccthWPyg.o:(.rodata._ZTI8Aquarium[typeinfo for Aquarium]+0x10): undefined reference to `typeinfo for Item'
/tmp/ccthWPyg.o:(.rodata._ZTI5Plant[typeinfo for Plant]+0x10): undefined reference to `typeinfo for Item'
/tmp/ccthWPyg.o:(.rodata._ZTI4Book[typeinfo for Book]+0x10): undefined reference to `typeinfo for Item'

Please help me out on what I need to do
kuntilanakAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brijesh_iaeCommented:
I didn't find the your files at the given path. From the errors mentioned in your problem description, it seems that you've virtual destructors in your code for which you've no definitions. Please provide the definitions for your virtual destructors.
The same applies to other member errors in the problem description. For nonvirtual member function also, it is unable to locate the definition of the functions.
0
kuntilanakAuthor Commented:
are you sure that you can't download the files?  well..here's my .cc file
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#include "Books.h"

/***************************************************************Book****************************************************************/

Book::Book(const String& title, int thickness, int weight)
: itsThickness(thickness), itsWeight(weight),
  itsName(title)
{}

Book::~Book()
{
    
}

int Book::minWidth() const{
	return itsThickness;
}

int Book::maxWeight() const{
	return itsWeight;
}

String Book::descrip() const{
	String result = "\'" + itsName + "\'";
	return result;
}

void Book::print() const
{
    cout << itsName << "(" << itsThickness << " mm, " << itsWeight << " dg)" << endl;
    //printf("%s (%d mm, %d dg)\n", itsName, itsThickness, itsWeight);
}



/***************************************************************Plant****************************************************************/

Plant::Plant(const String& name, int spread, int weight)
: plantName(name), plantSpread(spread),
  plantWeight(weight)
{}

Plant::~Plant()
{
    
}

int Plant::minWidth() const{
	return plantSpread;
}

int Plant::maxWeight() const{
	return plantWeight;
}

String Plant::descrip() const{
	String result = "\'A plant named " + plantName +"\'";
	return result;
}

void Plant::print() const
{
    printf("this needs modification\n");
}

/***************************************************************FishTank****************************************************************/

FishTank::FishTank(int base1, int base2, int height)
: tankBase1(base1), tankBase2(base2),
  tankHeight(height)
{ 
  aq_width = calWidth();
  aq_weight = calWeight();
}

FishTank::~FishTank()
{
    
}

int FishTank::minWidth() const{
	return aq_width;
}

int FishTank::maxWeight() const{
	return aq_weight;
}

String FishTank::descrip() const{
	char buffer[33];
	snprintf(buffer, sizeof(buffer), "%d", aq_width);
	String width(buffer);
	String result = "\'" + width + "mm wide fish tank" +"\'";
	return result;
}

void FishTank::print() const
{
    printf("this needs modification\n");
}

int FishTank::calWidth(){
	return (tankBase1>tankBase2)? tankBase1:tankBase2;
}

int FishTank::calWeight(){
	return (int)(tankBase1 * tankBase2 * tankHeight * .0001);
}

/***************************************************************FishBowl****************************************************************/

FishBowl::FishBowl(int radius)    
:bowlRadius(radius)
{ 
  aq_width = calWidth();
  aq_weight = calWeight();
}


FishBowl::~FishBowl()
{
    
}

int FishBowl::minWidth() const{
	return aq_width;
}


int FishBowl::maxWeight() const{
	return aq_weight;
}

String FishBowl::descrip() const{
	char buffer[33];
	snprintf(buffer, sizeof(buffer), "%d", aq_width);
	String width(buffer);
	String result = "\'" + width + "mm high fish bowl" +"\'";
	return result;
}

void FishBowl::print() const
{
    printf("this needs modification\n");
}

int FishBowl::calWidth(){
	return 2*bowlRadius;
}

int FishBowl::calWeight(){
	return (4/3)*PI*bowlRadius;
}


void Item::enableDebug(bool toggle)
{
  // Do whatever
}

Bookcase::Bookcase(int id)
: itsShelfCount(0), itsId(id) {}

Bookcase::~Bookcase()
{
    for (int i = 0; i < itsShelfCount; i++)
        delete itsShelves[i];
}

bool Bookcase::addShelf(int width, int capacity)
{
    if (itsShelfCount >= MaxShelves)
        return false;
    
    itsShelves[itsShelfCount++] = new Shelf(width, capacity);
    return true;
}

bool Bookcase::add(Item *bp) const
{
    if (itsShelfCount == 0) return false;

    Shelf *target = NULL;
    int available = -1;
    for (int i = 0; i < itsShelfCount; i++) {
        Shelf *sp = itsShelves[i];
        if (sp->can_hold(bp) && sp->available() > available) {
            target = sp;
            available = target->available();
            }
        }

    if (target == NULL)
        return false;

    target->add(bp);
    return true;
}

void Bookcase::print() const
{
    printf("Bookcase #%d\n", itsId);
    for (int i = 0; i < itsShelfCount; i++)
        itsShelves[i]->print();
}

Bookcase::Shelf::Shelf(int width, int capacity)
: itsWidth(width),
  itsMaxWeight(capacity),
  itsUsedWidth(0),
  itsUsedWeight(0),
  itsItemCount(0),
  itsMaxItems(ItemChunk),
  itsItems(new Item*[ItemChunk])
{}

void Bookcase::Shelf::add(Item *bp)
{
    assert(can_hold(bp));

    if (itsItemCount == itsMaxItems)
        expand();

    itsItems[itsItemCount++] = bp;
    itsUsedWeight += bp->maxWeight();
    itsUsedWidth += bp->minWidth();
}

void Bookcase::Shelf::print() const
{
    printf("--- Shelf (%d mm, %d dg) ---\n", itsWidth, itsMaxWeight);
    for (int i = 0; i < itsItemCount; i++) {
        printf("%2d: ", i+1);
        itsItems[i]->print();
        }
}

void Bookcase::Shelf::expand()
{
    Item **newItems = new Item*[itsMaxItems += ItemChunk];
    for (int i = 0; i < itsItemCount; i++)
        newItems[i] = itsItems[i];
    delete [] itsItems;
    itsItems = newItems;
}
    
bool Bookcase::Shelf::can_hold(Item *bp) const
{
    return itsUsedWeight + bp->minWidth() <= itsMaxWeight &&
        itsUsedWidth + bp->maxWeight() <= itsWidth;
}

int Bookcase::Shelf::available() const
{
    return itsWidth - itsUsedWidth;
}

Open in new window

0
kuntilanakAuthor Commented:
here's my .h, see if it helps
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

milindsmCommented:
Try making print method a pure virtual method in Item class...!!!
0
kuntilanakAuthor Commented:
here's my .h
0
kuntilanakAuthor Commented:
geez, the attach thing isn't attaching
#ifndef _Books_h_
#define _Books_h_

#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "String.h"

#define PI 3.14159265358979323846

using namespace std;

class Item{
public:
  //
  // Return the width of the Item in its thinnest acceptable orientation
  //
   virtual int minWidth() const = 0;
 
  //
  // Return the maximum weight of the Item.
  //
  virtual int maxWeight() const = 0;

  //
  // Return a description of the Item
  //
  virtual String descrip() const = 0;

  //
  // Print the description of the Item on standard output, followed by a newline.
  //
  virtual void print() const;

  //
  // Enable (or disable) debug descriptions. When enabled, the String produced
  // by descrip() includes the minimum width and maximum weight of the Item.
  // Initially, debugging is disabled.
  static void enableDebug(bool);

  //
  // Item needs a virtual destructor.
  virtual ~Item(){}
};

class Book : public Item {
    public:
        Book(const String& title, int thickness, int weight);
        ~Book();
	 int minWidth() const;
	 int maxWeight() const;
	 String descrip() const;
        void print() const;

    private:
        void operator=(Book&);
        Book(const Book&);
        int itsThickness, itsWeight;
        const String itsName;
};

class Plant : public Item{
   public:
	Plant(const String& name, int spread, int weight);
	 ~Plant();
	int minWidth() const;
	int maxWeight() const;
	String descrip() const;
       void print() const;

   private:
	int plantSpread;
	int plantWeight;
	const String plantName;
};

class Aquarium : public Item{
public:
  virtual int calWidth() = 0;   // Pure virtual function.
  virtual int calWeight() = 0;   // Pure virtual function.
  virtual ~Aquarium(){}
protected:
  int aq_width;
  int aq_weight;
};


class FishTank : public Aquarium{
    public:
       FishTank(int base1, int base2, int height);
       ~FishTank();
	int minWidth() const;
	int maxWeight() const;
	String descrip() const;
       void print() const;
	int calWidth();
	int calWeight();
    private:
        int tankBase1, tankBase2, tankHeight;
};


class FishBowl : public Aquarium{
     public:
       FishBowl(int radius);          
       ~FishBowl();
	int minWidth() const;
	int maxWeight() const;
	String descrip() const;
       void print() const;
	int calWidth();
	int calWeight();
    private:
       int bowlRadius;
};

class Bookcase {
    public:
        Bookcase(int id);
        int id() const { return itsId; }
        ~Bookcase();
        bool addShelf(int width, int capacity);
        bool add(Item *it) const;
        void print() const;

    private:
        class Shelf;
        static const int MaxShelves = 10;
        Shelf *itsShelves[MaxShelves];
        int itsShelfCount, itsId;

        void operator=(Bookcase&);
        Bookcase(const Bookcase&);
        
    class Shelf {
        public:
            Shelf(int width, int capacity);
              
            ~Shelf() { delete [] itsItems; }
    
            void add(Item *bp);
            void print() const;
    
            bool can_hold(Item *bp) const;
            
            int available() const;
            
        private:
            int itsWidth, itsMaxWeight,
            itsUsedWidth, itsUsedWeight;
            int itsItemCount, itsMaxItems;
            Item **itsItems;
            static const int ItemChunk = 100;
    
            void expand();
            void operator=(Shelf&);
            Shelf(const Shelf&);
            };
        };

#endif

Open in new window

0
kuntilanakAuthor Commented:
isn't it already pure virtual?
0
milindsmCommented:
nope.... its just virtual.....virtual void print() const;

make it

virtual void print() const = 0;
0
kuntilanakAuthor Commented:
yes that totally worked... may I know why it needs to be pure virtual? and why it didn't work out before?
0
milindsmCommented:
Since its not a pure virtual function, it must have a body which was missing.

So,
1. You can either make it pure virtual OR
2. You can implement (define it something like void Item::print() const {} ) it in your source.

both of the above options work...!!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.