Given the following test program: #include <sstream> #include <iostream>
class X : private std::ostringstream { public: template<typename a> X &operator<<(a arg) { #if 0 std::ostringstream &o= *this; o << arg; #else std::ostringstream::operator<<(arg); #endif return *this; } using std::ostringstream::str; }; int main(int argc, char **argv) { X x; x << "foo"; std::cerr << x.str() << std::endl; } The output that I get is: $ ./t 0x4014f0 ... or some other hexadecimal pointer value. If I change the "#if 0" to "#if 1" and compile the alternate version, I get the expected results: $ ./t foo After staring at this for a while, I can't see what the difference is here. It almost looks like "std::ostringstream::operator<<(arg)" ends up invoking std::ostringstream::operator<<(void *) even though arg's type is char * (or a const char *). -- Summary: Overloaded template losing type in invoking a superclass method? Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mrsam at courier-mta dot com GCC build triplet: x86_64-redhat-linux GCC host triplet: x86_64-redhat-linux GCC target triplet: x86_64-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34696