Must parameter of assignment operator be reference?

Posted by Tim on Stack Overflow See other posts from Stack Overflow or by Tim
Published on 2010-05-30T22:35:54Z Indexed on 2010/05/30 22:42 UTC
Read the original article Hit count: 231

When overloading assignment operator of a class in C++, must its parameter be reference?

For example,

class MyClass {
public:
...
MyClass & operator=(const MyClass &rhs);
...
}

Can it be

class MyClass {
public:
...
MyClass & operator=(const MyClass rhs);
...
}

?

Thanks!

© Stack Overflow or respective owner

Related posts about c++

Related posts about reference