Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Difference between (T&*) and T where T is a template (http://www.go4expert.com/forums/difference-t-t-t-template-t777/)

sharmila 3May2006 14:18

Difference between (T&*) and T where T is a template
 
Hi all,
One more doubt regarding pointers and reference.Somewhere I saw a code like this
Code: CPP

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.

coderzone 4May2006 11:18

Re: Difference between (T&*) and T where T is a template
 
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.

shabbir 4May2006 21:16

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

Originally Posted by coderzone
they want to be deleting the memory without even thinking of allocating the memory.

:D


All times are GMT +5.5. The time now is 06:01.