pointers

This is a discussion on pointers within the C++ Programming forums, part of the General Programming Boards category; I can't seem to get this access to the correct pointers. I have delared two header nodes as private members ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    pointers

    I can't seem to get this access to the correct pointers. I have delared two header nodes as private members in the class to point to the head and tail nodes of a linked list. When I run the constructor (see below), I get access to the header nodes, without any problem. But when I try to run another function on the nodes, especially IsEmpty, I get an access violation when I try to access header1. I have put in if statements in the constructor to check to see if the nodes are getting assigned properly with the memory allocation that is included in another function, and these tests are passed.


    //Here is the constructor. Dynamic memory allocation takes place
    // in functions "AllocXorStore()". header1->link is
    // an unsigned long int that will be typecast to be the address
    // of the next node.

    xorlist()
    {

    header1=AllocXorStore();
    header2=AllocXorStore();
    header1->info=header2->info=NULL;
    header1->link=0;
    header2->link=0;
    printf("\nHeader1->link = %d", (int)header1->link);
    //IsEmpty();
    Printfunct=NULL;
    Compfunct=NULL;
    Delfunct=NULL;
    if(header1!=NULL)
    printf("\n!NULL\n");
    };

    //checks to see if the list is empty
    int IsEmpty()
    {
    assert(header1);

    return(header1->link==0L&&header2->link==0L);
    };

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Could we see the code for AllocXorStore?
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    Sayeh
    Guest
    This post should be in the C++ section...

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    xorstore

    here is the code for the xorstore()

    xorptr AllocXorStr()
    {
    return (xorptr)malloc(sizeof(xorstr));
    };

    This is declared outside of the class. Why, I am not sure, but prof. says that it is necessary to do so.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MergeSort with array of pointers
    By lionheart in forum C Programming
    Replies: 18
    Last Post: 08-01-2008, 11:23 AM
  2. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 06:59 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM

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