Help me understand this compile error message. 
Author Message
 Help me understand this compile error message.

 Hi all,

 I am in the process of learning C++ and I am using a book titled
 "Teach yourself C++ programming in 21 days" by Jesse Liberty.

 I have reach chapter 15 and I was reproducing one of the examples
 and I get the following error message:

 'Part' is not a public base class of 'PartsCatalog'.

I am using Turbo C++ Version 3.1.

Here is  is the complete listing of the example. The error occurs when
I pass the address of a function as a parameter.
Thanks in advance for your help.
Thanks

==============================CUT HERE==============================
// demonstrate private inheritance

//********************************************************
// Description: Provide a linked list demonstration Program.
//
// Classes:  PART - Hold part numbers and potentially other
//                  information about parts
//
//           ParNode - acts as a node in a Partlist
//
//           PartList - provides mechanism for a linked
//                      list of parts
//
//
//********************************************************

#include <iostream.h>

typedef unsigned long ULONG;
typedef unsigned short USHORT;

// ******** Part ***************
class Part
{
 public:
   Part():itsPartNumber(1){}
   Part(ULONG PartNumber):itsPartNumber(PartNumber){}
   virtual ~Part(){};
   ULONG GetPartNumber() const {return itsPartNumber;}
   virtual void Display() const =0; //must be overridden
 private:
   ULONG itsPartNumber;

Quote:
};

//implementation of a pure virtual function so that
//derived class can chain up
void Part::Display() const
{
 cout << "\nPart Number: " << itsPartNumber << endl;

Quote:
}

// ********* Cart Part *********

class CarPart : public Part
{
 public:
  CarPart():itsModelYear(94){}
  CarPart(USHORT year, ULONG partNumber);
  virtual void Display() const { Part::Display(); cout << "Model year: " << itsModelYear << endl;}

 private:
  USHORT itsModelYear;

Quote:
};

CarPart::CarPart(USHORT year, ULONG partNumber):
itsModelYear(year),
Part(partNumber)
{

Quote:
}

//***************** AirPlane Part ************
class AirPlanePart : public Part
{
 public:
  AirPlanePart():itsEngineNumber(1){}
  AirPlanePart(USHORT EngineNumber, ULONG PartNumber);
  virtual void Display() const { Part::Display(); cout << "Engine No.: " << itsEngineNumber << endl;}

 private:
  USHORT itsEngineNumber;

Quote:
};

AirPlanePart::AirPlanePart(USHORT EngineNumber, ULONG PartNumber):
itsEngineNumber(EngineNumber),
Part(PartNumber)
{}

// ****************** Part Node *******************
class PartNode
{
 public:
  PartNode (Part *);
  ~PartNode ();
  void SetNext(PartNode *node) {itsNext=node;}
  PartNode *GetNext() const;
  Part *GetPart() const;

 private:
  Part *itsPart;
  PartNode *itsNext;

Quote:
};

PartNode::PartNode(Part *pPart ):
itsPart(pPart),
itsNext(0)
{

Quote:
}

PartNode::~PartNode()
{
 delete itsPart;
 itsPart=0;
 delete itsNext;
 itsNext=0;

Quote:
}

//Returns NULL if no next PartNode
PartNode *PartNode::GetNext() const
{
 return itsNext;

Quote:
}

Part *PartNode::GetPart() const
{
 return itsPart;

Quote:
}

//********************Part List ********************
class PartsList
{
 public:
  PartsList();
  ~PartsList();
  //Need copy Constructor and operator equals!
  Part *Find(ULONG &position, ULONG PartNumber) const;
  ULONG GetCount() const { return itsCount;}
  Part* GetFirst() const;
  static PartsList &GetGlobalPartList() { return GlobalPartsList;}
  void Insert(Part *);
  void Iterate(void (Part::*f)() const) const;
  Part* operator[](ULONG) const;

 private:
  PartNode *pHead;
  ULONG itsCount;
  static PartsList GlobalPartsList;

Quote:
};

PartsList PartsList::GlobalPartsList;

//Implementation for lists.....
PartsList::PartsList():
 pHead(0),
 itsCount(0)
{

Quote:
}

PartsList::~PartsList()
{
 delete pHead;
 pHead=0;

Quote:
}

Part* PartsList::GetFirst() const
{
 if (pHead)  //If head exist return first Part
  return (pHead->GetPart());
 else
  return (NULL);

Quote:
}

Part *PartsList::operator[](ULONG offSet) const
{
  //If Head exist, check offSet and return
  //appropriate element....
  PartNode *pNode=pHead;
  if (!pHead)
   return(NULL);
  if (offSet > itsCount)
   return(NULL);
  for(ULONG i=0; i < offSet; i++)
   pNode=pNode->GetNext();

  return(pNode->GetPart());

Quote:
}

Part* PartsList::Find(ULONG &position, ULONG PartNumber) const
{
 PartNode *pNode=0;

 for (pNode=pHead, position=0;
      pNode!=NULL;
      pNode=pNode->GetNext(), position++)
  {
   if(pNode->GetPart()->GetPartNumber() == PartNumber)
     break;
  }
 if (pNode==NULL)   //couldn't find it!
  return NULL;
 else
  return pNode->GetPart();

Quote:
}

void PartsList::Iterate(void (Part::*func)()const) const
{
  if (!pHead)
   return;     //empty list
  PartNode *pNode=pHead;
  do
   {
     (pNode->GetPart()->*func)();
   } while (pNode=pNode->GetNext());

Quote:
}

void PartsList::Insert(Part *pPart)
{
 PartNode *pNode= new PartNode(pPart);
 PartNode *pCurrent=pHead;
 PartNode *pNext=0;

 ULONG New = pPart->GetPartNumber();
 ULONG Next=0;
 itsCount++;

 if (!pHead)
  {
   pHead=pNode;
   return;
  }

 //if this one is smaller than the head
 //then this one is the new head
 if (New < pHead->GetPart()->GetPartNumber())
 {
   pNode->SetNext(pHead);
   pHead=pNode;
   return;
 }

 for (;;)
  {
   if (!pCurrent->GetNext())
    {
     // we have reached the end.
     pCurrent->SetNext(pNode);
     return;
    }

   // if this one goes after this one and before the next
   // then insert it ther, otherwise get the next
   pNext=pCurrent->GetNext();
   Next=pNext->GetPart()->GetPartNumber();
   if (Next > New)
    {
     pCurrent->SetNext(pNode);
     pNode->SetNext(pNext);
     return;
    }
   pCurrent=pNext;
  }

Quote:
}

class PartsCatalog : private PartsList
{
  public:
    void Insert(Part *);
    ULONG Exists(ULONG PartNumber);
    Part *Get(int PartNumber);
    operator+(const PartsCatalog &);
    void ShowAll(){Iterate(Part::Display);}
   // here is a work around. but this defies the abstraction
   //between the client  of PartsCatalog and Part
   //void ShowAll(void (Part::*pFunc)()const) const;

  private:

Quote:
};

// temp. work around
/*void PartsCatalog::ShowAll(void (Part::*pFunc)() const) const
{
 Iterate(pFunc);
Quote:
}

*/

void PartsCatalog::Insert(Part *newPart)
{
  ULONG partNumber = newPart->GetPartNumber();
  ULONG offset;

  if (!Find(offset,partNumber))
   {
    PartsList::Insert(newPart);
   }
  else
   {
    cout << partNumber << " was the ";
    switch (offset)
     {
       case 0: cout << "first "; break;
       case 1: cout << "second "; break;
       case 2: cout << "third "; break;
       default: cout << offset +1 << "th ";
     }
    cout << "entry.  Rejected!\n";
   }

Quote:
}

ULONG PartsCatalog::Exists(ULONG PartNumber)
{
  ULONG offset;

  Find(offset, PartNumber);
  return(offset);

Quote:
}

Part *PartsCatalog::Get(int PartNumber)
{
 ULONG offset;

 Part *thePart=Find(offset,PartNumber);
 return(thePart);

Quote:
}

void main()
{
  PartsCatalog pc;
  Part *pPart=0;
  ULONG PartNumber;
  USHORT value;
  ULONG choice;

  while (1)
  {
    cout << "(0)Quit (1)Car (2)Plane: ";
    cin >> choice;

    if (!choice)
     break;
    cout << "New PartNumber?: ";
    cin >> PartNumber;

    if (choice ==1)
     {
      cout << "Model Year?:";
      cin >> value;
      pPart = new CarPart(value, PartNumber);
     }
    else
     {
      cout << "Engine Number?:";
      cin >> value;
      pPart = new AirPlanePart(value,PartNumber);
     }

    pc.Insert(pPart);
  } // of while

 //temp. work around
 // void (Part::*pFunc)() const= Part::Display;
 // pc.ShowAll(pFunc);
 pc.ShowAll();

Quote:
}



Sat, 15 Nov 1997 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. don't understand compile-time error

2. Help !!!! Error message when compile

3. Help !!!! Error message when compile

4. Does anyone understand this error message ???

5. An error message I don't understand...

6. don't understand error message

7. Help on my C code, dont understand how to fix my compiler errors (PLEASE HELP)

8. Please help : cannot understand error mesg.

9. help!! Errors I don't understand

10. Help in understanding the compiler error

11. error message while compiling c

12. Wierd error message after compiling with cc

 

 
Powered by phpBB® Forum Software