Casting and inheritance, oh my.
Sam Varshavchik
mrsam@courier-mta.com
Thu Apr 5 00:16:00 GMT 2012
If I feed the following to gcc 4.6.3:
#include <sstream>
class Y : public std::ostringstream {
public:
using std::ostringstream::operator<<;
};
Y y;
template<typename x> void cast(const x &z)
{
(std::ostringstream &)y << z;
}
template<typename x> void inherit(const x &z)
{
y << z;
}
int int_type;
char char_array[10];
I get the following results:
cast(int_type); // This compiles
inherit(int_type); // This compiles
cast(char_array); // This compiles
inherit(char_array); // Failure, gcc complains about an ambiguous overload.
Why does it matter, how the operator gets resolved?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20120405/a4aa106d/attachment.sig>
More information about the Gcc-help
mailing list