On Feb 21, 2021, at 3:58 AM, Roland Bock via SG7 <sg7@lists.isocpp.org> wrote:On 19.02.21 15:34, David Rector wrote:Here is another class of non-trivial examples to consider:
```
template<class T, class U>
class Sum {
T t;
U u;
public:
Sum(T &t, U u) : t(t), u(u) {}
// Methods: the union of the methods of T and U.
// Wherever they "share" a method, such that names and
// signatures of method reflections m_t and m_u are the same
// (not necc. via inheritance) that method is implemented
// to return t.[:m:](…) + u.[:m:](…). Otherwise, it returns
// t.[:m:](…) or u.[:m:](…) individually.
// Conversion operators: construct from the relevant fields,
// but for any data T shares with U, need to add in the other’s
// data to the initializer.
explicit operator T();
explicit operator U();
};
I understand the composition with forwarding functions. But what would be a real-world use case for `t.[:m:](…) + u.[:m:](…)`?
Note that `operator+` might not be defined for the return type. Also, the signatures might differ in just the return type.