Difference between (T&*) and T where T is a template

Discussion in 'C' started by sharmila, May 3, 2006.

  1. sharmila

    sharmila New Member

    Joined:
    Mar 24, 2006
    Messages:
    75
    Likes Received:
    1
    Trophy Points:
    0
    Hi all,
    One more doubt regarding pointers and reference.Somewhere I saw a code like this
    Code:
    template<class T>
    class Abc
    {
    public:
    	Abc(T* aPtr){iPtr=aPtr; }
    	~Abc(){delete iPtr; }
    	T*& Ptr() const{return (T*&)iPtr; }
    	T& operator ()(){return *iPtr; }
    	void operator=(void* aNull)
    	{
    		delete iPtr;
    		iPtr = (T*)aNull;
    	}
    private:
    	T* iPtr;
    };
    Like this the class is defined.
    Here T*& is nothing but T.i.e here Ptr() is returning T.Instead of T why they have taken T*&.
    I have another doubt also.Is the code correct?I mean deleting iPtr in overloaded =
    operator.
    Thanks in advance.

    Regards,
    sharmila.
     
    Last edited by a moderator: May 3, 2006
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    Probably the code is never going to run successfully. They have written the code with the frame in mind that they want to be deleting the memory without even thinking of allocating the memory.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    :D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice