S
sam.barker0
Hi,
I have designed a class with an overloaded = operator.
The problem is that
whenever I invoke the method
like
const myclass<char> astring=another_object;
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<typename T>
myclass<T>& myclass<T>:perator=(const myclass<T>& rhs)
{
if(this != &rhs)
{
//free the allocated memory
//allocate again
this->var1=rhs.var1;
this->head=rhs.head;
//call another method
recursively_copy(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<char> astring=another_object;
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<typename T>
myclass<T>& myclass<T>:perator=(const myclass<T>& rhs)
{
if(this != &rhs)
{
//free the allocated memory
//allocate again
this->var1=rhs.var1;
this->head=rhs.head;
//call another method
recursively_copy(head,rhs.head);
}
return *this;
}
Why is this happening
Cheers,
Sam