'how can std::bind copy the passed object?

I have a question.

I know that std::bind is a copy constructible function.

so when a object is passed to parameter, it call copy constructor.

And if I want to prevent it, I should use std::ref.

what I want to know is how can it happen?

int main() { A a; (1) A b{a}; (2) A c{std::ref(a)} (3) }

in this case, (1) calls constructor of class A. (2) and (3) call copy constructor.

int main() { A a; ① auto f = std::bind(func, a); ② auto g = std::bind(func, std::ref(a)); ③ } in this case, ② calls copy constructor of class A but ③ doesn't call constructor.

I want to know specific way to copy object.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source