Newbie question about accesing member functions


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Newbie question about accesing member functions

  1. #1
    Robert Ayzma Guest

    Newbie question about accesing member functions


    If you take a look at this code you can see a working implementation of a
    2way linked list(not all of it). I have included the things that puzzle me
    as comments in the code my hope is you can explain why I can't use the member
    function in my class when declaring a variable as
    // not working
    Node variable1;
    variable1.append(p);

    but I have to do it like this to get the method of the class.
    //working
    Node* variable2;
    variable2->append(p);


    #include<iostream.h>

    class node {
    public:
    node(int d, node* h=0,node* t=0) : data(d), next(h),prev(t) {}
    int data;
    node* next;
    node* prev;
    void append(node* p);
    };
    node* p;
    node* head = 0;
    node* tail = 0;

    void node::append (node* p) {
    if (head==NULL){
    head=p;
    p->prev=NULL;
    } else {
    p->prev=tail;
    tail->next=p;
    }
    tail=p;
    p->next=NULL;
    }

    void main(void)
    {
    // Node q;
    p = new node(1,head,tail);
    p->append(p); // this works
    // q.append(p); this doesn't work WHY?????
    cout << p->data << endl;

    }


  2. #2
    Danny Kalev Guest

    Re: Newbie question about accesing member functions

    aren't you confusing node for Node? You should be aware that uppercase
    and lowercase letters are distinct in C++. Try declaring q as follows:

    node q; // not Node q

    Danny

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center