CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    75

    Got One Error In My Code

    it says

    1> c:\users\hani\bookstoreassignment\bookstoreassignment\thecode.cpp(304) : see reference to class template instantiation 'linkListType<Type>' being compiled

    anyway here is out my code ,, actually its pretty long


    PHP Code:
    # include <iostream>
    # include <iomanip>
    #include <string>
    #include <cassert>
    using namespace std;

    struct book
    {
     
    string title;
     
    string author;
     
    float price;
     
    long ISBN;
    };

    template <class Type>
    struct Nodetype
    {
     
    Type info;
     
    Nodetype <Type> *link;
    };

    template <class Type>
    class 
    linkListType

     
    friend void splitList(const linkListType <Type> & ,linkListType <Type> & L1 linkListType <Type> & L2);
     private:
      
    Nodetype <Type> *first;
      
    Nodetype <Type> *last;
      
    int count;
     public:
      
      
    linkListType();
      
    bool isEmpty();
      
    void print();
      
    void printItem(const Type Item);
      
    void destroylist();
      
    int listSize();
      
    Type front();
      
    Type back();
      
    bool Search(const Type Item);
      
    void insertfirst(const Type Item);
      
    void insertlast(const Type Item);
      
    void deleteItem(const Type Item);
      
    void splitList (linkListType <Type> & L1 linkListType <Type> & L2);
      ~
    linkListType();
    };
     

    template <class Type>
    linkListType <Type> :: linkListType()
    {
     
    first=NULL;
     
    last=NULL;
     
    count=0;
    }

    template <class Type>
    bool linkListType <Type> :: isEmpty()
    {
     if(
    first==NULL && last==NULL && count==0)
      return 
    true;
     else
      return 
    false;
    }


    template <class Type>
    void linkListType <Type> :: destroylist()
    {
     
    Nodetype <Type> *temp;
     while (
    first != NULL)
     {
      
    temp=first;
      
    first=first->link;
      
    delete temp;
     }
     
    last=NULL;
     
    count=0;
    }


    template <class Type>
    int linkListType <Type> :: listSize()
    {
     return 
    count;
    }

    template <class Type>
    Type linkListType <Type> :: front()
    {
     
    assert(last!= NULL);
     return 
    first->info;
    }

    template <class Type>
    Type linkListType <Type> :: back()
    {
     
    assert(last!= NULL);
     return 
    last->info;
    }

    template <class Type>
    bool linkListType <Type> :: Search(const Type Item)
    {
     
    Nodetype <Type> *curr;
     
    bool found=false;
     
    curr=first;
     while (
    curr != NULL && !found)
     {
     if(
    curr-> info.ISBN == Item.ISBN)
     {
      
    found=true;
      break;
     }
     else
      
    curr=curr->link;
     }
     return 
    found;
    }

    template <class Type>
    void linkListType <Type> :: insertfirst(const Type Item)
    {
     
    Nodetype <Type> *newnode;
     
    newnode = new Nodetype <Type>;
     
    assert (newnode !=NULL);
     
    newnode->info Item;
     
    newnode->link =first;
     
    first=newnode;
     
    count++;
     if(
    last==NULL)
      
    lastnewnode;
    }

    template <class Type>
    void linkListType <Type> :: insertlast(const Type Item)
    {
     
    Nodetype <book> *newnode;
     
    newnode = new Nodetype <Type>;
     
    assert (newnode !=NULL);
     
    newnode->info=Item;
     
    newnode->link =NULL;
     if(
    first==NULL)
     {
      
    firstnewnode;
      
    last=newnode;
      
    count++;
     }
     else
     {
      
    last->link =newnode;
      
    last=newnode;
      
    count++;
     }
    }

    template <class Type>
    void linkListType <Type> :: deleteItem(const Type Item)
    {
     
    Nodetype <Type> * curr;
     
    Nodetype <Type> * pre;
     
    bool foundfalse;
     if(
    first==NULL)
      
    cerr<<"cannot delete from an empty list\n";
     else
     {
      if(
    first->info.ISBN == Item.ISBN)
      {
       
    curr first;
       
    first first->link;
       
    count--;
       if (
    first == NULL)
        
    last=NULL;
       
    delete curr;
      }
      else
      {
       
    pre first;
       
    curr=first->link;
       while (
    curr != NULL && !found)
       {
        if(
    curr->info.ISBN != Item.ISBN)
        {
         
    pre=curr;
         
    curr=curr->link;
        }
        else
         
    found=true;
       }
       if(
    found)
       {
        
    pre->link curr->link;
        
    count--;
        if (
    last == curr)
        
    lastpre;
        
    delete curr;
       }
       else
        
    cout<<"the item that you want to delete is not availabel\n";
       }
      }
    }
     
    template <class Type>
    linkListType <Type> :: ~linkListType()
    {
     
    distroylist();
    }


    template <class Type>
    void linkListType <Type> :: print()
    {
     
    Nodetype <Type> *curr;
     
    curr=first;
     
    cout<<"The book title /t "<<"The aother /t "
     
    <<" The price /t"<<" The ISBN";
     
    cout<<"\n\n";
     while (
    curr != NULL)
     {
      
    cout<<curr->info.title<<"/t"<<curr->info.author
      
    <<"/t"<<curr->info.price<<"/t"<<curr->info.ISBN
      
    <<endl;
      
    curr=curr->link;
     }
    }


    template <class Type>
    void linkListType <Type> :: printItem(const Type Item)
    {
     
    Nodetype <Type> *curr;
     
    bool found=false;
     
    curr=first;
     while (
    curr != NULL && !found)
     {
      if(
    curr-> info.ISBN == Item.ISBN)
      {

       
    cout<<curr->info.title<<"/t"<<curr->info.author
       
    <<"/t"<<curr->info.price<<"/t"<<curr->info.ISBN
       
    <<endl;
       
    found=true;
      }
      else
       
    curr=curr->link;
     }
     if (!
    found)
      
    cout<<"the item is not available\n";
    }

    template <class Type>
    void linkListType <Type> :: splitList (linkListType <Type> & L1 linkListType <Type> & L2)
    {
     
    Nodetype <Type> * curr;
     
    curr=first;
     if( 
    isEmpty())
      
    cerr<<"the list is empty\n";
     else if (
    first == last && count ==1)
     {
      if(
    first->info.price 20)
       
    L2.insertlast(first->info);
      else
       
    L1.insertlast(first->info);
     }
     else
      while(
    curr !=NULL)
      {
       if(
    curr->info.price 20)
        
    L2.insertlast(curr->info);
       else
        
    L1.insertlast(curr->info);
       
    curr=curr->link;
      }
    }

    template <class Type>
    void splitList (linkListType <Type> & L,linkListType <Type> & L1 linkListType <Type> & L2)
    {
     
    Nodetype <Type> * curr;
     
    curr=L.first;
     if( 
    L.isEmpty())
      
    cerr<<"the list is empty\n";
     else if (
    L.first == L.last && L.count ==1)
     {
      if(
    L.first->info.price 20)
       
    L2.insertlast(L.first->info);
      else
       
    L1.insertlast(L.first->info);
     }
     else
      while(
    curr !=NULL)
      {
       if(
    curr->info.price 20)
        
    L2.insertlast(curr->info);
       else
        
    L1.insertlast(curr->info);
       
    curr=curr->link;
      }
    }

    void main()
    {
     
    linkListType <book> list;
     
    linkListType <booklist1;
     
    linkListType <booklist2;
     
    book y;
     
    int x;
     
    cout<<"Input your choice\n";
     
    cout<<"enter\t0\t.Exit the program "<<endl;
     
    cout<<" \t1\t.Insert new book's info"<<endl;
     
    cout<<" \t2\t.Delete a book (according to ISBN)"<<endl;
     
    cout<<" \t3\t.print all books"<<endl;
     
    cout<<" \t4\t.print one book info (according to ISBN)"<<endl;
     
    cout<<" \t5\t.check if there are books"<<endl;
     
    cout<<" \t6\t.to check how many books there"<<endl;
     
    cout<<" \t7\t.To print the first book info"<<endl;
     
    cout<<" \t8\t.To print the last book info"<<endl;
     
    cout<<" \t9\t.To search about a book (according to ISBN)"<<endl;
     
    cout<<" \t10\t.To find the most expensive book"<<endl;
     
    cout<<" \t11\t.To print the books of praice < OR = 20 BD"<<endl;
     
    cout<<" \t12\t.To print the books of praice > 20 BD"<<endl;
     
    cout<<" \t13\t.To distroy all the info about books"<<endl;
     
    cout<<"Enter your choice :\t ";
     
    cin>>x;
     
    cout<<endl;
     while(
    != 0)
     {
      switch(
    x)
      {
       case 
    1:
       {
        
    cout<<endl;
        
    cout<<"enter the title\t\t ";
        
    cin>>y.title;
        
    cout<<"\nenter ISBN\t\t";
        
    cin>>y.ISBN;
        
    cout<<"\nenter the price\t\t ";
        
    cin>>y.price;
        
    cout<<"\nenter the author ";
        
    cin>>y.author;
        
    cout<<endl<<endl;
          list.
    insertlast(y);
          
       }
       break;
       case 
    2:
       {
        
    cout<<endl;
        
    cout<<"Enter the ISBN of the book you want to delete\t";
        
    cin>>y.ISBN;
        list.
    deleteItem (y);
       }
       break;
      case 
    3:
      {
       
    cout<<endl;
       list.print();
      }
      break;
      case 
    4:
      {
       
    cout<<"\nEnter the ISBN of the book you want to print\n";
       
    cin>>y.ISBN;
       list.
    printItem(y);
      }
      break;
      case 
    5:
      {
       
    int a= list.isEmpty();
       if (
    a== false)
       
    cout<<"Yes there are "<<list.listSize()<<" books\n";
       else
       
    cout<<"Sorry there is no books entered\n";
      }
      break;
      case 
    6:
      {
       
    cout<<"\n Ther are \t"<<list.listSize()<<"\t books";
      }
      break;
      case 
    7:
      {
       
    book n;
       
    n=list.front();
       
    cout<<"\n The first book is\n"<<n.title<<endl;
      }
      break;
      case 
    8:
      {
       
    book n;
       
    n=list.back();
       
    cout<<"\nThe last book is\n"<<n.title<<n.author<<n.price<<n.ISBN<<endl;
      }
      break;
      case 
    9:
      {
       
    cout<<"\nEnter the ISBN of the book you want to print\n";
       
    cin>>y.ISBN;
       list.
    printItem(y);
      }
      break;

      case 
    10:
      {
       list.
    splitList (list1,list2);
       
    list1.print();
      }
      break;
      case 
    12:
      {
       list.
    splitList (list1,list2);
       
       
    list2.print();
      }
      break;
      case 
    11:
      {
       
    cout<<"you chose to distroy the list\n";
       list.
    destroylist();
      }
      break;
      default:
       
    cout<<"Invalid choice\n";
      }
      
    cout<<"Your are in main menu again"<<endl;
      
    cout<<"enter\t0\t.Exit the program "<<endl;
      
    cout<<" \t1\t.Insert new book's info"<<endl;
      
    cout<<" \t2\t.Delete a book (according to ISBN)"<<endl;
      
    cout<<" \t3\t.print all books"<<endl;
      
    cout<<" \t4\t.print one book info (according to ISBN)"<<endl;
      
    cout<<" \t5\t.check if there are books"<<endl;
      
    cout<<" \t6\t.to check how many books there"<<endl;
      
    cout<<" \t7\t.To print the first book info"<<endl;
      
    cout<<" \t8\t.To print the last book info"<<endl;
      
    cout<<" \t9\t.To search about a book (according to ISBN)"<<endl;
      
    cout<<" \t10\t.To find the most expensive book"<<endl;
      
    cout<<" \t11\t.To print the books of praice < OR = 20 BD"<<endl;
      
    cout<<" \t12\t.To print the books of praice > 20 BD"<<endl;
      
    cout<<" \t13\t.To distroy all the info about books"<<endl;
      
    cout<<"Enter your choice :\t ";
      
    cin>>x;
      
    cout<<endl;
     }
     
    cout<<"you are outing the program\n";


  2. #2
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: Got One Error In My Code

    Where do you define distroylist() ?

  3. #3
    Join Date
    Jul 2010
    Posts
    75

    Re: Got One Error In My Code

    the function header in public

    and the implantation down

  4. #4
    Join Date
    Jul 2010
    Posts
    75

    Re: Got One Error In My Code

    ok thx mate fixed it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured