Hello, I am a bit surprised that GCC (Ubuntu 4.3.2-1ubuntu11) 4.3.2 picks the char* operator rather than the const char* one in the code attached... I thought I'd report it in case someone case explain it to me, or in case it might be a bug.
Thanks an regards, Hervé
#include <iostream> #include <cstring> class Test { public: operator const char* () const { return "abcdef"; } operator char* () { return strdup("ghijkl"); } #ifdef AMBIGUOUS char operator[](unsigned int) const { return 'a'; } #endif }; int main() { Test t; if (t[0] == 'g') { std::cout << "wrong one" << std::endl; } if (t[0] == 'a') { std::cout << "right one" << std::endl; } return 0; }