Thread: about pointers and node

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    96

    about pointers and node

    Hi,

    I have a program as:

    Code:
     
    
    Event* remove()
     {
     if(size>0)
     {
     Event* e=nodes[0];
     
    for (int j=0; j<size-2;j++)
     
    nodes[j]=nodes[j+1];
     
    size=size-1;
     
    rear=rear-1;
     
    if( size==0) rear=-1;
     
    return e;
     
    }
    I have some questions about this small program, when do we actually need to have a return type as pointer with the method remove?

    If we have a method as :

    Event* e=nodes[0];

    Does this mean that we are passing an element or data from the 1st location(0) of the node to the pointer Event?

    Regards,

  2. #2
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    It should give a pointer to the 0 element of nodes which I can only assume is an array of Event pointers. It seems like the code would benefit from a vector though.

    It seems like this is probably a member of a class. I can only assume since you never declare variables and looking at how things are laid out in general. There are a few things wrong with this code as it stands. I assume this is school work so lets see if you can find them.
    Last edited by ~Kyo~; 12-10-2013 at 02:39 AM. Reason: class?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quadtree Node -> pointers to the children node
    By yahn in forum C++ Programming
    Replies: 2
    Last Post: 04-13-2009, 06:38 PM
  2. Replies: 0
    Last Post: 09-16-2008, 05:04 AM
  3. Replies: 8
    Last Post: 04-28-2008, 02:46 AM
  4. Stack functions as arrays instead of node pointers
    By sballew in forum C Programming
    Replies: 8
    Last Post: 12-04-2001, 11:13 AM
  5. Replies: 5
    Last Post: 10-04-2001, 03:42 PM