Need help with HybridList class errors......

This is a discussion on Need help with HybridList class errors...... within the C++ Programming forums, part of the General Programming Boards category; I am in desperate need to figuring out why my program has 11 errors on line 191 and 1 error ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    22

    Unhappy Need help with HybridList class errors......

    I am in desperate need to figuring out why my program has 11 errors on line 191 and 1 error on line 130. If someone could please assist me, I would greatly appreciate your help.

    Code:
    //************************************************************
     void HybridList::Print() const
    
    // Postcondition:
    //     component members of all nodes (if any) in linked list
    //     have been output
        
    {
        mePtr currPtr = head;                                 // Loop control pointer
    
        while (currPtr != NULL)
        {
            cout << currPtr->lName << endl;            // Line 130 Error C2679
            currPtr = currPtr->link;
        }
    }
    //*************************************************************
    void HybridList::Insert( /* in */ ComponentType item )
    
    // Precondition:
    //     component members of list nodes are in ascending order
    //  && item is assigned
    // Postcondition:
    //     New node containing item is in its proper place
    //       in linked list
    //  && component members of list nodes are in ascending order
    
    {
        mePtr currPtr;       // Moving pointer
        mePtr prevPtr;       // Pointer to node before *currPtr
        mePtr newMePtr;    // Pointer to new node
    
        // Set up node to be inserted
    
        newMePtr = new me;
        newMePtr->lName = item;
    
        // Find previous insertion point
        prevPtr = NULL;
        currPtr = head;
    
        while (currPtr != NULL && item > currPtr->lName)   // Line 191 Error C2784
         {
            prevPtr = currPtr;
            currPtr = currPtr->link;
        }
    
        // Insert new node
    
        newMePtr->link = currPtr;
        if (prevPtr == NULL)
            head = newMePtr;
        else
            prevPtr->link = newMePtr;
    }

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    And the errors are?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    These are the errors:

    1. Hybrid List Assignment\HybridList.cpp(130): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'ComponentType' (or there is no acceptable conversion)

    2. HybridList.cpp(191):error C2784: 'bool std:perator >(const std::_Ptrit<_Ty,_Diff,_Pointer2,_Reference2,_Point er2,_Reference2> &,const std::_Ptrit<_Ty,_Diff,//_Pointer,_Reference,_Pointer2,_Reference2> &)' : could not deduce template argument for 'const std::_Ptrit<_Ty,_Diff,_Pointer2,_Reference2,_Point er2,_Reference2> &' from 'ComponentType'

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    Does ComponentType have operator<< and operator> defined?

  5. #5
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    What is mePtr defined as?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  6. #6
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    ComponentType is a string. This is how I declared it:

    Code:
    // This is the file that declares the itemType data type
    
    #ifndef COMPONENTTYPE_H
    #define COMPONENTTYPE_H
    
    #include <iostream>
    
    using namespace std;
    
    typedef string ComponentType;
    
    #endif

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    Code:
    typedef me* mePtr;
    struct me
    {
    	ComponentType lName;
    	ComponentType fName;
    	ComponentType mName;
    	ComponentType title;
    	ComponentType companyName;
    	ComponentType streetAddress;
    	ComponentType city;
    	ComponentType state;
    	ComponentType zipCode;
    	ComponentType phoneNumber;
    	ComponentType faxNumber;
    	ComponentType emailAddress;
    	mePtr link;
    };

  8. #8
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Why typedef string as ComponentType?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  9. #9
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    I used typedef string as ComponentType for an easier string variable pass to the Hybrid class.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    You didn't #include <string>.

  11. #11
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    That solved that problem. Thanks

  12. #12
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    Since you don't use anything from <iostream> in the ComponentType header, and since there is no need for a using directive when you are only using one name from the std namespace, that header would be better to look like this:
    Code:
    #ifndef COMPONENTTYPE_H
    #define COMPONENTTYPE_H
    
    #include <string>
    
    typedef std::string ComponentType;
    
    #endif

  13. #13
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    Another problem but it's in the Print function of the Hybrid class. I don't get any errors but the output is not what I expected. I need all of the elements of the struct to display as output but the program only display the first element of the struct and the other elements are blank lines. So the program knows that the elements are there but instead of text it's several blank lines.

    My code is below. Thanks.

    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include "HybridList.h"
    
    using namespace std;
    
    struct me
    {
    	ComponentType lName;
    	ComponentType fName;
    	ComponentType mName;
    	ComponentType title;
    	ComponentType companyName;
    	ComponentType streetAddress;
    	ComponentType city;
    	ComponentType state;
    	ComponentType zipCode;
    	ComponentType phoneNumber;
    	ComponentType faxNumber;
    	ComponentType emailAddress;
    };
    
    int main()
    {
    	HybridList list1;
    	me contact;
    	
    	char another;
    	
    	cout << "Enter last name: ";
    	getline(cin, contact.lName);
    	cout << "Enter first name: ";
    	getline(cin, contact.fName);
    	cout << "Enter middle name: ";
    	getline(cin, contact.mName);
    	cout << "Enter title: ";
    	getline(cin, contact.title);
    	cout << "Enter company name: ";
    	getline(cin, contact.companyName);
    	cout << "Enter street address: ";
    	getline(cin, contact.streetAddress);
    	cout << "Enter city: ";
    	getline(cin, contact.city);
    	cout << "Enter state: ";
    	getline(cin, contact.state);
    	cout << "Enter zip code: ";
    	getline(cin, contact.zipCode);
    	cout << "Enter phone number: ";
    	getline(cin, contact.phoneNumber);
    	cout << "Enter fax number: ";
    	getline(cin, contact.faxNumber);
    	cout << "Enter e-mail address: ";
    	getline(cin, contact.emailAddress);
    
    	list1.Insert(contact.lName);
    	list1.Print();
    
    	cout << "Would you like to enter another contact(Y/N): ";
    	cin >> another;
    
                    .....  program continues .....
    }
    //*************************************************************
    void HybridList::Print() const
    
    // Postcondition:
    //     component members of all nodes (if any) in linked list
    //     have been output
    
    {
        mePtr currPtr = head;    // Loop control pointer
    
        while (currPtr != NULL)
        {
             cout << currPtr->lName << endl;           
             cout << currPtr->fName << endl;
             cout << currPtr->mName << endl;
             cout << currPtr->title << endl;
             cout << currPtr->companyName << endl;
             cout << currPtr->streetAddress << endl;
             cout << currPtr->city << endl;
             cout << currPtr->state << endl;
             cout << currPtr->zipCode << endl;
             cout << currPtr->phoneNumber << endl;
             cout << currPtr->faxNumber << endl;
             cout << currPtr->emailAddress << endl;
             currPtr = currPtr->link;
        }
    }


    I think it have something to do with passing the struct to the class.

  14. #14
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    Your Insert function should probably be taking a me object instead of a ComponentType. You aren't inserting the lname into the list, you are inserting an entire me object.

  15. #15
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    So I should pass contact to the insert function because contact is an object of the me struct. So item would then be an object of me.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  2. Class Errors (LNK2005)
    By NMZ in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2005, 02:52 PM
  3. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 03:22 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. class member access denied
    By chiqui in forum C++ Programming
    Replies: 2
    Last Post: 05-27-2002, 02:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21