Objective-C++ overload resolution no longer working?
Objective-C++ overload resolution no longer working?
- Subject: Objective-C++ overload resolution no longer working?
- From: Derrick Bass <email@hidden>
- Date: Sat, 12 Nov 2005 19:57:24 -0800
I've been using some code like this:
std::ostream& operator<<(std::ostream& o, NSObject* ob) { return o <<
[ob description]; }
(of course, there's also an operator<< for NSString*) in order to
integrate objective-C into the more flexible C++ iostreams system.
This used to work just fine. I could pass in any object and print it
to any stream.
But the recent upgrade to Xcode 2.2 (and gcc 4.0.1) seems to have
broken that.
Now, if someobject is not explicitly an NSObject*,
cout << someobject
give a bunch of errors about ambiguous overload resolution. I have to
cast subclasses to an NSObject* first:
cout << (NSObject*) someobject
which is annoying. I tried redefining the operator<< to use id
instead of NSObject*. That sort of worked; some objects would
compile, and some wouldn't.
Was I relying on a bug or undefined behavior? Or is the new behavior
a bug?
Derrick
PS: Here's the error message, redacted for length:
error: ambiguous overload for 'operator<<' in 'std::operator<< [with
_Traits = std::char_traits<char>](((std::basic_ostream<char,
std::char_traits<char> >&)(+(+ std::operator<< [with _Traits =
std::char_traits<char>](((std::basic_ostream<char,
std::char_traits<char> >&)(& std::clog)), ((const char*)"Track ")))-
>std::basic_ostream<_CharT, _Traits>::operator<< [with _CharT =
char, _Traits = std::char_traits<char>](i))), ((const char*)" type
")) << #'obj_type_ref' not supported by dump_expr#<expression error>
(#'obj_type_ref' not supported by dump_expr#<expression error>
(((objc_object*)tracks), _OBJC_SELECTOR_REFERENCES_20, ((unsigned int)
i)), _OBJC_SELECTOR_REFERENCES_24, QTTrackMediaTypeAttribute)'
/usr/include/c++/4.0.0/bits/ostream.tcc:125: note: candidates are:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long int) [with _CharT = char, _Traits =
std::char_traits<char>] <near match>
/usr/include/c++/4.0.0/bits/ostream.tcc:159: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits
= std::char_traits<char>] <near match>
and so on...
/Users/derrick/code/MS/objc++glue.h:11: note:
std::ostream& operator<<(std::ostream&, NSString*)
/Users/derrick/code/MS/objc++glue.h:13: note:
std::ostream& operator<<(std::ostream&, NSObject*)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden