1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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:
    734
    Likes Received:
    37
    Trophy Points:
    0
    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,283
    Likes Received:
    364
    Trophy Points:
    83
    :D
     

Share This Page