I get this error while compiling my class linked list with constructors. I wanted to do a copy assignment operator, but i get this error 'list::list' names the constructor, not the type. the line is:
list::list& operator= (const list &l)
list is my the name of my class
If you are defining your operator=
function inside your class definition, declare it thus:
class list {
...
list& operator=(const list&) { ... return *this; }
};
If you are defining your operator=
function outside your class definition, declare it as in this complete and correct example:
class list {
public:
list& operator=(const list&);
};
list& list::operator=(const list&) {
return *this;
}
int main() {}
This error is pretty self-explanatory.
Use this code:
list& operator= (const list &l)
Outside a class declaration, you have to precise in which scope belongs the function:
list& list::operator= (const list &l)
// ^^^^^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With