0

I want to use async to execute such a function in the environment of C++17.Here is my class

class Item {
    public:
        int v=1;
        Item() {printf(" construct \n");};
        Item(const Item&it) {printf(" construct  copy \n");}
        Item( Item&& it) {printf("  universal copy \n");}
        ~Item() {printf("destruction \n");}
    };

Here is my function

    Item func(float r) {return Item(); }

Here is my main function

int main()
    { 
        auto  sft=std::async(launch::async,func, 1);
    };
    

Here is my problem: the compiler indicates that: "Item & item:: operator = (const item &)": attempt to reference a deleted function", However, when I remove the move construct function; it passes the compile stage, with the execution of copy construct function 2 times, could someone tell me why? I don't want to call the copy construct function, I just want to move the result to the sft. thanks a lot!

shenuo
  • 11
  • 1
  • 2
    You're missing the assignment operators. See [rule of 3/5/0](https://stackoverflow.com/questions/4172722/what-is-the-rule-of-three). – rustyx Apr 06 '21 at 08:08
  • 1. you can select your code and press `ctrl + K` to format it as source code so it is displayed correctly. 2. why do you move a function pointer? – Timo Apr 06 '21 at 08:11
  • I don't want to call construct copy function, I just want to move the Item entity to the sft, – shenuo Apr 06 '21 at 08:16
  • I got what you two mean,thanks a lot,It seems an assignment operators calling is necessary, Thank you very much – shenuo Apr 06 '21 at 08:45

0 Answers0