Undefined and redefined errors

advertisements

I have a client code file that includes three .h files for three different object types (UnsortedType, CompData, ItemType). UnsortedType.h also has a #include ItemType.h

After including a header guard for the client code, and the same guard within the UnsortedType file, the only error I had left was an ambiguous compiling error for the function ObjectFromFile. When I comment out the function, I get several Undefined errors for UnsortedType and ItemType data, so I get the feeling that there is something else going on.

This program is meant to bring in data from an inFile object ItemType item, convert to to a specific format and check for validity, then add the data to specific lists of UnsortedType, depending on certain aspects of the data. (valid, invalid, RAM and Disk size, laptop data, desktop data).

Here is my error:

runItemType.cxx: In function âUnsortedType ObjectFromFile(std::ifstream&, UnsortedType&,     CompDataType, ItemType&, UnsortedType&, UnsortedType&, UnsortedType&)â:
runItemType.cxx:215: error: âCompareRAMAndDiskâ was not declared in this scope

Here is my client code:

#include <iostream>
  #include <fstream>
  #include <iomanip>
  #include <string>
  #include "UnsortedType.h"
  #include "CompData.h"
  #ifndef ITEM_TYPE_H
  #define ITEM_TYPE_H
  #include "ItemType.h"
  using namespace std;

  UnsortedType ObjectFromFile(ifstream& inFile, UnsortedType& list, CompDataType Data, ItemType& item, UnsortedType& laptopList, UnsortedType& desktopList, UnsortedTyp$
  void CompareRAMAndDisk(ItemType item, UnsortedType& RAMList);
  void DoCommandP(ItemType& item, UnsortedType list, CompDataType Data, ofstream& outFile);
  void DoCommandK(ofstream& outFile, UnsortedType& desktopList);
  void DoCommandL(ofstream& outFile, UnsortedType& laptopList);
  void DoCommandM(ofstream& outFile, UnsortedType RAMList);
  void DoCommandD(UnsortedType& list, ItemType item);
  UnsortedType DoCommandA(ifstream& inFile, UnsortedType& list, CompDataType Data, ItemType& item, UnsortedType& laptopList, UnsortedType& desktopList);
  void PrintHeader(ofstream& outFile);

  int main()
  {
   // declare and open file streams
 ifstream inFile;
   ofstream outFile;

   inFile.open("in.data");
   outFile.open("out.data");
   outFile.setf(ios::fixed);
   outFile.precision(2);

   ItemType item;
   UnsortedType list;
   UnsortedType laptopList;
   UnsortedType desktopList;
   UnsortedType RAMList;
   UnsortedType invalidList;
   CompDataType Data;
   char command;
   int length;
   bool full;
   bool found;

   // Check input file
   if(inFile.fail() || outFile.fail())
   {
     cout << "File Failure" << endl;
     return 1;
   }

   list.MakeEmpty();
   outFile << "*~< Lab Report >~" << endl;

   while(inFile)
   {
     inFile >> command;
     if(command == 'P')
     {
       invalidList.PrintList(outFile);
       outFile << endl;
 length = list.LengthIs();
       if(length == 0)
       {
         outFile << "~->List is empty! No print!" << endl;
       }
     }
     else
     {
       PrintHeader(outFile);

       DoCommandP(item, list, Data, outFile);
     }

   if(command = 'A')
   {
     full = list.IsFull();
     if(full)
       outFile << "~->List is full! No add!" << endl;
     else
 invalidList = DoCommandA(inFile, list, Data, item, laptopList, desktopList);
   }
   if(command == 'D')
   {
     length = list.LengthIs();
     if(length == 0)
       outFile << "~->List is empty! No delete!" << endl;
     else
       DoCommandD(list, item);
   }
   if(command == 'L')
   {
     DoCommandL(outFile, laptopList);
   }
   if(command == 'K')
   {
     DoCommandK(outFile, desktopList);
   }
     if(command == 'M')
     {
       DoCommandM(outFile, RAMList);
     }
   }
   outFile << "*< end >*" << endl;
   inFile.close();
   outFile.close();
   return 0;
  }
#endif

 //*****************************************************************************************************************************
  void DoCommandP(ItemType& item, UnsortedType list, CompDataType Data, ofstream& outFile)
  {

   int length;
   length = list.LengthIs();
   list.PrintList(outFile);

   outFile << endl;
   if(Data.numDesktop > 0)
   outFile << "Average cost of Desktops: $" << item.avgCostOfDesktop() << endl;

   else
     outFile << "Average cost of Desktops: " << "No Desktops" << endl;

   if(Data.numLaptop > 0)
     outFile << "Average cost of Laptops: $" << item.avgCostOfLaptop() << endl;

   else
     outFile << "Average cost of Laptops: " << "No Laptops" << endl;

   if(Data.numDesktop > 0 || Data.numLaptop > 0)
   {
     outFile << "High Price: $" << item.HighPriceComputer() << endl;
     outFile << "Low Price: $" << item.LowPriceComputer() << endl;
   }
 else
   {
     outFile << "High Price: " << "No valid computer data" << endl;
     outFile << "LowPrice: " << "No valid computer data" << endl;
   }
   outFile << endl;

   outFile << "SE135: %" << (Data.count135 / length);
   outFile << "SE136: %" << (Data.count136 / length);
   outFile << "SE145: %" << (Data.count145 / length);
   outFile << endl;
   outFile << "*** " << Data.invalidCount << " Record";
   outFile << endl;
   }

  //**********************************************************************************************
  UnsortedType ObjectFromFile(ifstream& inFile, UnsortedType& list, CompDataType Data, ItemType& item, UnsortedType& laptopList, UnsortedType& desktopList, UnsortedTyp$
  {
    UnsortedType invalidList;
    Data.computerTypeConvert = "l";
    Data.invalidCount = 0;
    Data.numDesktop = 0;
    Data.numLaptop = 0;
    Data.count135 = 0;
    Data.count136 = 0;
    Data.count145 = 0;

    item.ReadRd(inFile);
    while(inFile)
    {
     // function calls for reading and assigning values to private data
     Data.valid = item.ValidData();
     item.SetComputerType(Data.computerTypeConvert);

     // Check data validity
     if(Data.valid)
     {
       Data.computerType = item.ComputerTypels();
 Data.location = item.Locationls();
       if(Data.computerType == "l")
       {
         item.FindAvgCostLaptop();
         Data.numLaptop = Data.numLaptop + item.NumberComputerls();
         laptopList.InsertItem(item);
       }
       if(Data.computerType == "d")
       {
         item.FindAvgCostDesktop();
         Data.numDesktop = Data.numDesktop + item.NumberComputerls();
         desktopList.InsertItem(item);
       }
       if(Data.numDesktop + Data.numLaptop > 0)
       {
         item.FindLowPriceComputer();
         item.FindHighPriceComputer();
       }
       if(Data.location == "SE135")
         Data.count135++;
       if(Data.location == "SE136")
         Data.count136++;
       if(Data.location == "SE145")
         Data.count145++;
       CompareRAMAndDisk(item, RAMList);
       list.InsertItem(item);
       item.ReadRd(inFile);
     }
     else
     {
      Data.invalidCount++;
      invalidList.InsertItem(item);
     }
    }
     return invalidList;
   }
  //*********************************************************************************************
  void PrintHeader(ofstream& outFile)
 {
    const string DASH8 = "--------";
    outFile << "*~< Lab Report >~*" << endl << endl;
    outFile << left << setw(16) << "IdNumber" << setw(24) <<  "P R 0 C E S S O R" << setw(17) << "RAM Size";
    outFile << left << setw(15) << "Disk Size" << setw(17) << "Computer Type" << setw(12) << "C o s t";
    outFile << left << setw(9) << "Location" << endl;
    outFile << left << setw(16) << DASH8 << setw(24) <<  "-----------------" << setw(17) << DASH8;
    outFile << left << setw(15) << "---------" << setw(17) << "-------------" << setw(12) << DASH8;
    outFile << left << setw(9) << DASH8 << endl;

  }
  //**************************************************************************************************************
  UnsortedType DoCommandA(ifstream& inFile, UnsortedType& list, CompDataType Data, ItemType& item, UnsortedType& RAMList, UnsortedType& laptopList, UnsortedType& deskt$
  {
     UnsortedType invalidList;
     invalidList = ObjectFromFile(inFile, list, Data, item, laptopList, desktopList, RAMList);
     return invalidList;
  }
  //*******************************************************************************************
  void DoCommandD(UnsortedType& list, ItemType item)
  {
    list.DeleteItem(item);
  }
  //******************************************************************************************
  void DoCommandK(ofstream& outFile, UnsortedType& desktopList)
  {
    desktopList.PrintList(outFile);
  }
  //******************************************************************************************
  void DoCommandL(ofstream& outFile, UnsortedType& laptopList)
  {
    PrintHeader(outFile);
    laptopList.PrintList(outFile);
  }
  //******************************************************************************************
  void DoCommandM(ofstream& outFile, UnsortedType RAMList)
  {
    bool ramData;
 PrintHeader(outFile);
    RAMList.PrintList(outFile);
  }
  //******************************************************************************************
  void CompareRAMAndDisk(ItemType item, UnsortedType RAMList)
  {
    string RAMInt;
    string DiskInt;
    string RAM;
    string Disk;
    int index;

    Disk = item.Diskls();
    RAM = item.RAMls();
    index = Disk.find(' ');
    DiskInt = Disk.substr(0, (index - 1));
    Disk = Disk.substr(index);

    index = RAM.find(' ');
    RAMInt = RAM.substr(0, (index - 1));
    RAM = RAM.substr(index);

    if((RAMInt >= "16" && RAM == "GB") && (DiskInt == "2" && Disk == "TB"))
    RAMList.InsertItem(item);
  }

 //*****************************************************************************************

Any help is welcome! (Also, if you see logic errors, please let me know! I can generally fix them on my own, but the faster I finish this, the better!)


You function declaration is:

void CompareRAMAndDisk(ItemType item, UnsortedType& RAMList);

and your function definition is:

void CompareRAMAndDisk(ItemType item, UnsortedType RAMList);

See the difference? From the looks of it you'd want to change the function definition to use an UnsortedType &.