1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
// reference_wrapper::operator=
#include <iostream> // std::cout
#include <functional> // std::reference_wrapper
int main () {
int a,b;
// reference_wrapper assignment:
a=10; b=20;
std::reference_wrapper<int> wrap1 (a);
std::reference_wrapper<int> wrap2 (b);
wrap1 = wrap2;
++wrap1; ++wrap2;
std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';
std::cout << '\n';
// note the difference with:
a=10; b=20;
int& ref1 (a);
int& ref2 (b);
ref1 = ref2;
++ref1; ++ref2;
std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';
return 0;
}
|