Hi,
I have designed a class with an overloaded = operator.
The problem is that
whenever I invoke the method
like
const myclass<charast ring=another_ob ject;
my overloaded gets invoked and everything is fine.
but if I write
const myclass<char>& astring=another _object;
I guess the synthesised overload function takes place instead of my
overloaded function.
astring is a shallow copy of another_object.
My overloaded method is defined as
template<typena me T>
myclass<T>& myclass<T>::ope rator=(const myclass<T>& rhs)
{
if(this != &rhs)
{
//free the allocated memory
//allocate again
this->var1=rhs.var 1;
this->head=rhs.hea d;
//call another method
recursively_cop y(head,rhs.head );
}
return *this;
}
Why is this happening
Cheers,
Sam
I have designed a class with an overloaded = operator.
The problem is that
whenever I invoke the method
like
const myclass<charast ring=another_ob ject;
my overloaded gets invoked and everything is fine.
but if I write
const myclass<char>& astring=another _object;
I guess the synthesised overload function takes place instead of my
overloaded function.
astring is a shallow copy of another_object.
My overloaded method is defined as
template<typena me T>
myclass<T>& myclass<T>::ope rator=(const myclass<T>& rhs)
{
if(this != &rhs)
{
//free the allocated memory
//allocate again
this->var1=rhs.var 1;
this->head=rhs.hea d;
//call another method
recursively_cop y(head,rhs.head );
}
return *this;
}
Why is this happening
Cheers,
Sam
Comment