Casting to void*.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eli112233
    New Member
    • Apr 2010
    • 2

    Casting to void*.

    Hello :)
    well as the title says, i have a problem with casting to void*.

    so, I made a linked list class at c++. heres the list :

    class LinkedList
    {

    struct LinkedListObjec t
    {
    void* data;
    LinkedListObjec t *nxt_obj;
    }*list_head;

    void AddObj(void* data);
    }

    So, at the AddObj function, I have a little problem. thats the function:

    void LinkedList::Add Obj(void* data)
    {
    LinkedListObjec t *object;
    if(list_head==N ULL)
    {

    object->data=data;

    object->nxt_obj=NULL ;

    list_head=objec t;

    return;
    }
    ...
    }

    when i try to use the function on other class, i mean when im trying to add an object to the list , the program shut down at the line object->data=data.
    for example:
    Location l; (Location is a class at my prog)
    ...
    list.AddObj(&l) .
    as I said the program shut down at the line object->data=data..

    help?
  • akdemirc
    New Member
    • Sep 2008
    • 26

    #2
    that should because you use LinkedListObjec t *object in add method without allocating it

    Comment

    • eli112233
      New Member
      • Apr 2010
      • 2

      #3
      thank you!!!

      Comment

      Working...