[comp.lang.c++] Printing pointers using operator<<

sdm@cs.brown.edu (Scott Meyers) (06/08/89)

I want to overload operator<< so that I can print the value of a pointer
(in hex).  This is what I've tried:

    ostream& operator<<(ostream& s, void *ptr)
    { return s << hex(unsigned(ptr)); }

My goal is to have this function be called for a variable of type T* iff
there is no operator<< function that takes a T* as an argument.  g++ 1.35
compiles this without complaint, but cfront 1.2 says:

    error:   << defined both as operator <<() and ostream::operator <<()

I looked in <stream.h> to find a conflicting definition of operator<< that
takes a void* as an argument, but I failed to find one.  Other experiments
I performed convince me that cfront doesn't consider void* to be an "exact
match" for a T*.  

If someone could explain what is happening, I'd appreciate it.

Scott
sdm@cs.brown.edu