* g++ 3.1.1: Implicit-conversion vs. [ ] operator conflict
@ 2002-08-08 12:54 Wirawan Purwanto
0 siblings, 0 replies; only message in thread
From: Wirawan Purwanto @ 2002-08-08 12:54 UTC (permalink / raw)
To: gcc
I just compiled GNU C++ 3.1.1 under Redhat Linux 7.3, and I have a problem
with the pre-existing code:
Suppose I have a class named CHAR, which implement a C-like char* with
built-in memory management. I would like to have it converted automatically
to const char* (needed by C subroutines, for example strlen, etc.); but I
also want to have a [] operator that check the character index. So, I
implemented it in the following way:
class CHAR
{
public:
...
inline operator const char* () const { return ...; }
inline char& operator[] (int idx) { ...; }
};
The use:
CHAR mystring;
...
mystring[0] = 'a';
In the previous version (g++ 3.1) it compiles OK. But with g++ 3.1.1, it
screams at the last line (mystring[0] = 'a';) with the following message:
sourcecode:line: choosing `char& CHAR::operator[](unsigned int)' over
`operator[]', because worst conversion for the former is better than worst
conversion for the latter
Then it would halt. What error have I made? I suppose that the class's
operator[] should precede the standard const char*'s [] operator (because
that's what I want also). Please point to the C++ standard if I've violated
something.
Thanks,
Wirawan
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-08-08 12:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-08 12:54 g++ 3.1.1: Implicit-conversion vs. [ ] operator conflict Wirawan Purwanto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).