Need help with linked list

This is a discussion on Need help with linked list within the C++ Programming forums, part of the General Programming Boards category; How can I access the private data members of the other class. There are two classes - a recordClass and ...

  1. #1
    kit
    kit is offline
    Registered User
    Join Date
    Oct 2001
    Posts
    6

    Need help with linked list

    How can I access the private data members of the other class. There are two classes - a recordClass and databaseClass

    // recordClass declaration
    recordClass {

    public:

    // set and get functions

    private:
    string studentName;
    double Grade;
    .....
    }

    =================================
    // databaseClass declaration

    struct listNode{
    recordClass item;
    listNode* next;
    }

    databaseClass {

    public:

    // constructor and destructor

    // insert and delete functions

    void insert(string, double....);

    private:
    int size;
    listNode* head;
    }

    =============================================
    // insert function

    void databaseClass::insert(string name, double gpa...)
    {

    listNode* cur = head;
    listNode* prev = NULL;

    recordClass temp;

    // QUESTION: how can I put the gpa into temp so that I can
    // compare it with whatever is in the list. I am trying to insert
    // a record in the sorted list.

    recordClass temp = gpa.getGpr();

    while (cur ! = NULL && cur->item.getGpr() < temp) {
    prev = cur;
    cur = cur->next;
    }


    HELP PLEASE!!!!!!!!!

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    With the friend keyword, you can designate either the specific functions or the classes whose functions can access not only public members but also protected and private members.

  3. #3
    kit
    kit is offline
    Registered User
    Join Date
    Oct 2001
    Posts
    6
    Can you give me an example on this? I haven't learn how to use 'friend' before. Thanks.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    I'm more than happy to help but learning something quickly is not always the best way to learn it for the long run. Take a look at your manual. Then ask a specific question and I'm more than happy to answer it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 11:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 11:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

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