Print pointers

This is a discussion on Print pointers within the C++ Programming forums, part of the General Programming Boards category; ok so i am trying to print an int that is in a point but it wont let me, this ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    9

    Print pointers

    ok so i am trying to print an int that is in a point but it wont let me, this is what i have...
    Code:
    void linkedQueue::addRear(el_t newNum)
    {    
         Node *rear;
         Node *front;
         
         if(count==0)
         {
               rear=new Node;
               rear->elem=newNum;
               front=rear;
         }
         else
         {
               rear->next=new Node;
               rear=rear->next;
               rear->elem=newNum;
         }
    
         count++;
    
    void linkedQueue::displayAll()
    {
         cout<<rear->elem;
    }
    }
    i kno that will not print the whoe list, but im trying to start by just printing one and i cant!!! lol why is this wrong?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    What is the definition of Node? What is the problem that you face? A compile error? Runtime output not what you expected? How does it not work?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    Code:
    struct Node 
    {
           int elem; 
           Node *next; 
    };
    and all im trying to do is print the int at rear->elem, but when i do it says
    'elem' has not been declared

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    Well, I note that you are using rear as a member variable in displayAll(), but you also declared a local Node* variable named rear in addRear(). Are you sure you have a Node* member variable named rear, and that the local variable rear in addRear() is really what you want?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    im trying to make a linked list that these functions can manipulate. so i have a list and addRear() adds to the rear, displayAll() shows everything in the list, etc.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    I guessed as much... the problem should just be that you are using local variables in your member functions but you think you are using member variables.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    ya i suspected that (complete n00b if you couldnt tell already lol)
    Code:
    #ifndef linkedQueue_H
    #define linkedQueue_H
    
    #include<iostream>
    
    using namespace std;
    
    struct Node 
    {
           int elem;
           Node *next;
    };
    
    class linkedQueue
    {  
          typedef int el_t;
             
          public:
                 linkedQueue();
                 ~linkedQueue();
                 
                 void addRear(el_t newNum);
                 void deleteFront(el_t oldNum);
                 
                 bool isEmpty();
                 int getSize();
                 void displayAll();
                 
          private:
                  int *front,*rear,count;
                  void queueError(char* mesg);
    };
    
    #endif
    is what if have now, and when i put in 'Node *rear;' it gives me all sorts of crap for it. isnt that how i would allow all the functions to use it?

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    Code:
    int *front,*rear,count;
    You declared them as int* instead of Node*.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    ooooooooo wow, that would make a difference. thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  2. Pointers on pointers to pointers please...
    By Morgan in forum C Programming
    Replies: 2
    Last Post: 05-16-2003, 11:24 AM
  3. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM
  5. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 06:53 PM

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