'list :: list' names constructor, not type

I get this error when compiling my linked class list with constructors. I wanted to make a copy assignment statement, but I get this error "list :: list" constructor names, not type names. line:

list::list& operator= (const list &l) 

list is my class name

+4
source share
2 answers

This error is pretty clear.

Use this code:

 list& operator= (const list &l) 

Outside of the class declaration, you must determine exactly in which area the function belongs:

 list& list::operator= (const list &l) // ^^^^^^ 
+12
source

If you define your operator= function inside your class definition, declare it this way:

 class list { ... list& operator=(const list&) { ... return *this; } }; 

If you define your operator= function outside the definition of your class, 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() {} 
+4
source

Source: https://habr.com/ru/post/1442136/


All Articles