A
Alfonzo Morra
I've the ff code in cp assignmenent cstor:
PB& PB:
perator=( const PB& b) {
if ( this != &b ) {
PB *pb = new PB( b ) ;
this = pb ; // <- Compiler barfs here
}
return *this ;
}
The error msg is : "'=' : left operand must be l-value". I seem to be
getting my references and pointers mixed up. if (this) is a pointer,
what is it pointing to ?. I rember reading somewhere that the (this)
pointer points to the current instance of the class or the "live"
object). If this indeed the case, then I see no reason why I cannot
assign (this) to another valid pointer.
Could someone please point out the correct way to implement this cp
assignment cstor?. Tks
Al
PB& PB:
if ( this != &b ) {
PB *pb = new PB( b ) ;
this = pb ; // <- Compiler barfs here
}
return *this ;
}
The error msg is : "'=' : left operand must be l-value". I seem to be
getting my references and pointers mixed up. if (this) is a pointer,
what is it pointing to ?. I rember reading somewhere that the (this)
pointer points to the current instance of the class or the "live"
object). If this indeed the case, then I see no reason why I cannot
assign (this) to another valid pointer.
Could someone please point out the correct way to implement this cp
assignment cstor?. Tks
Al