
Untitled
By: a guest on
Jun 26th, 2012 | syntax:
None | size: 0.88 KB | hits: 12 | expires: Never
Derived assignment operator and perfect forwarding
include <iostream>
struct foo
{
foo &operator=(const foo &)
{
std::cout << "base copy assignmentn";
return *this;
}
foo &operator=(foo &&)
{
std::cout << "base move assignmentn";
return *this;
}
};
struct bar: foo
{
template <typename T>
bar &operator=(T &&x)
{
std::cout << "derived generic assignmentn";
foo::operator=(std::forward<T>(x));
return *this;
}
};
int main()
{
bar b, c;
b = c;
b = bar{};
}
derived generic assignment
base copy assignment
base move assignment
derived generic assignment
base copy assignment
derived generic assignment
base move assignment
operator=(X&&);
operator=(const X&&);
operator=(volatile X&&);
operator=(const volatile X&&);