Re: Weird error on templates‏

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Panos C. C. wrote:
I get a very weird error in a simple and pretty straightforward piece of code involving 2 templates.


        RsrcPtr<Type>& operator=(RsrcPtr<Type> &a)
        {
            p = a.p;
            a.p = NULL;
        }

...
    RsrcPtr<B> niaou;
    niaou = bs.foo();

I think the main problem is taking a non const reference to a temporary object.

I don't quite understand the purpose of using RsrcPtr<Type> instead of just RsrcPtr inside the definition of

template<typename Type> class RsrcPtr

So I would have expected the operator= to be

       RsrcPtr& operator=(RsrcPtr const &a)
       {
           p = a.p;
           a.p = NULL;
           return *this;
       }

But if there was a reason for <Type> as you used it, just add the const and the return

       RsrcPtr<Type>& operator=(RsrcPtr<Type> const &a)
       {
           p = a.p;
           a.p = NULL;
           return *this;
       }




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux