c++ - explicitly-defaulted copy assignment operator must return MyClass & -


// task.h class task { public:     task() = default;     task(const task &) = delete;     ~task() = default;     task(task &&) = default;     const task & operator= (const task &) = default; };   /main.cpp #include <iostream> #include "task.h"  int main() {     task t;     std::cout<<"hello world"<<std::endl;     return 0; } 

i'm coding c++ on mac os. when compile code above: g++ main.cpp, error below:

error: explicitly-defaulted copy assignment operator must return 'task &'

i don't understand @ all. operator= can return non-const reference here? executed same code in windows , worked without error. mac os has special c++ standard?

the problem use = default.
http://en.cppreference.com/w/cpp/language/copy_assignment

if = default used, type of return must non-const reference. whereas if code this: const task & operator= (const task &t){}, works without error.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -