Overloading reference operator

Samkit Jain samkit.feeds@gmail.com
Sun Apr 25 13:39:00 GMT 2010


Yes my question is why does'nt assignment operator work out of the box ?

On Sun, Apr 25, 2010 at 12:02 AM, Andrew Haley <aph@redhat.com> wrote:
> On 04/24/2010 07:07 PM, Andrew Haley wrote:
>> On 04/24/2010 06:30 PM, Samkit Jain wrote:
>>> template<class T>
>>> MyClass
>>> {
>>>  public:
>>>     MyClass() : m_data(10) { }
>>>     operator T&() { return m_data; }
>>>  private:
>>>     T m_data;
>>> };
>>
>> I think this example does what you want:
>>
>> template<class T> class
>> MyClass
>> {
>> public:
>>   MyClass() : m_data(10) { }
>>   operator T&() { return m_data; }
>>   T& operator= (const T &t) { m_data = t; return *this; }
>> private:
>>   T m_data;
>> };
>
> I'm sorry, I think I misunderstood your question.  You're asking why
>
>  instance++;
>
> works, but, say
>
>  instance = instance + 1;
>
> doesn't.  Apologies.
>
> Andrew.
>



More information about the Gcc-help mailing list