[linux] OT: g++2.95/3.2 and ambiguous overload
Peter Mikula
mico na pobox.sk
Neděle Prosinec 1 11:20:34 CET 2002
hello,
prilozeny kod sa da skompilovat na g++2.95.3 bez problemov, ale na
g++3.2 to zdochne s:
ambig.cc: In function `int main()':
ambig.cc:25: ambiguous overload for `AmbigTest& << const char[21]' operator
ambig.cc:10: candidates are: AmbigTest AmbigTest::operator<<(C) [with C = const char*]
ambig.cc:16: AmbigTest AmbigTest::operator<<(const C&) [with C = char[21]]
je mi jasne o com ta chyba je, ale neviete niekto ako sa to da obist ?
Da sa nejako definovat precedence, ze by som povedal ze chcem pouzit
referenciu ked je to mozne ... ?
--
mico
Any technology distinguishable from
magic is insufficiently advanced
------------- další část ---------------
#include <iostream>
using namespace std;
class AmbigTest {
public:
/** This member writes a class that supports referencing to the buffer.
* @param c The object to be written
* @return The response object, for further writing.
*/
template<class C>
AmbigTest& operator<<(const C& c) {
cerr << c;
return *this;
}
/** This member writes everything that does not allow referencing, but
* supports writing, to the buffer.
* @param c The object to be written
* @return The response object, for further writing.
*/
template<class C>
AmbigTest& operator<<(const C c) {
cerr << c;
return *this;
}
};
int main() {
AmbigTest test;
test << "This is an AmbigTest" << endl;
}
Další informace o konferenci linux