Thread: What is *& ???

  1. #1
    Roelant
    Guest

    Question What is *& ???

    I am trying to use a function looking like this:

    function (Item *&)

    and I am breaking my head over the '*&'

    Does anyone know what it means ?

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    a reference to a pointer to an item
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Roelant
    Guest

    Smile

    it is a bit scary, but that was enough info already...

    I got it running.

    Thanks !

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    It also means trouble, function is going to change your pointer ugh, do I have to keep a copy to delete it later? Is function going to "helpfully" delete it for me, what if I want to send it a pointer to something on the stack or in an array? Such code is not fit for consumption by the general public. You might come up with an elegant hack somewhere deep in the bowels of your own library, but never expose such things to the poor users, and it's still got bad idea written all over it.

  5. #5
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    it's usefull for things like linked-lists
    lets say you have a linked list that follows the struct like this:
    Code:
    struct node
    {
    	int id;
    	node* next;
    };
    and in the main, you had the pointer to the begining, but you wanted to clear the whole thing, recursively... you would need to be able to change the pointer otherwise when your done... it'll be pointing to a place it shouldn't
    A common way to not get confused is to do something like:
    Code:
    typedef node* nodeptr;
    and then
    Code:
    int deletelist(nodeptr &root);
    These are the most common uses I can think of right now. Usually changing pointers in a function is a bad idea because you can't be sure how your pointer will return to you.


    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  6. #6
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    So it's simply passing a pointer by reference.
    none...

Popular pages Recent additions subscribe to a feed