Link to home
Create AccountLog in
Avatar of LuckyLucks
LuckyLucks

asked on

returning a dereferenced pts in C++

A&
A::operator= (const A& a) {
    if (this == &a)
        return (*this); <----
}


Does the above make sense? shouldn't we be returning this and not *this?
SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of LuckyLucks
LuckyLucks

ASKER

actually let's revisit this.

A& would return the address of the object. *this the value. they are not the same.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Best split.
share pts and close.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
completed.
Good to hear that reopening the question helped you better understand the issue.