F
fungus
I have some classes which have a "writeTo()" function
but no operator<<. I want to fix it so that they
all have an operator<< (for consistency).
Can I do something like this:
template <class T>
DataDest& operator<<(DataDest& d, const T& t)
{
t.writeTo(d);
return d;
}
I tried the above but I get errors like "no operator
found which takes a right-hand operand of type XXX".
Do I need to write all the operator<< and operator>>
functions by hand?
Also, a peeve: Why can't the compiler write operator==
and operator< for me automatically? I have some structs
with about 50 members in them (mostly float values) and
to write/maintain operator==/operator< functions for
them is a pain (not to mention bug-prone).
I'm sure the compiler could do this for me automatically
in exactly the same way that it generates operator= and
copy constructors.
Is there a good reason why this wasn't done? Something
I'm missing...?
--
<\___/>
/ O O \
\_____/ FTB. For email, remove my socks.
We’re judging how a candidate will handle a nuclear
crisis by how well his staff creates campaign ads.
It’s a completely nonsensical process.
but no operator<<. I want to fix it so that they
all have an operator<< (for consistency).
Can I do something like this:
template <class T>
DataDest& operator<<(DataDest& d, const T& t)
{
t.writeTo(d);
return d;
}
I tried the above but I get errors like "no operator
found which takes a right-hand operand of type XXX".
Do I need to write all the operator<< and operator>>
functions by hand?
Also, a peeve: Why can't the compiler write operator==
and operator< for me automatically? I have some structs
with about 50 members in them (mostly float values) and
to write/maintain operator==/operator< functions for
them is a pain (not to mention bug-prone).
I'm sure the compiler could do this for me automatically
in exactly the same way that it generates operator= and
copy constructors.
Is there a good reason why this wasn't done? Something
I'm missing...?
--
<\___/>
/ O O \
\_____/ FTB. For email, remove my socks.
We’re judging how a candidate will handle a nuclear
crisis by how well his staff creates campaign ads.
It’s a completely nonsensical process.