Thread overview
need explicit cast to convert from A to char const *
Aug 22, 2003
Christof Meerwald
Aug 22, 2003
Walter
Aug 24, 2003
Christof Meerwald
Aug 24, 2003
Walter
August 22, 2003
Hi,

struct A
{
  inline operator char *() { return 0; }
  inline operator const char *() const { return 0; }
};

int main()
{
  A a;
  const char *c = a;
  // Error: need explicit cast to convert
  // from: A
  // to  : char const *
  // (works with DMC 8.34, but doesn't work with DMC 8.35.8n)

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw@jabber.at mailto cmeerw at web.de
August 22, 2003
I have a question about this. The first conversion converts a char* to a const char*, the second converts the argument from A to const A. I.e. both add a const conversion, doesn't that make it ambiguous?

"Christof Meerwald" <cmeerw@web.de> wrote in message news:bi5j0r$1e8g$1@digitaldaemon.com...
> Hi,
>
> struct A
> {
>   inline operator char *() { return 0; }
>   inline operator const char *() const { return 0; }
> };
>
> int main()
> {
>   A a;
>   const char *c = a;
>   // Error: need explicit cast to convert
>   // from: A
>   // to  : char const *
>   // (works with DMC 8.34, but doesn't work with DMC 8.35.8n)
>
>   return 0;
> }
>
>
> bye, Christof
>
> --
> http://cmeerw.org                                 JID: cmeerw@jabber.at mailto cmeerw at web.de


August 24, 2003
On 22 Aug 2003, Walter wrote:
> I have a question about this. The first conversion converts a char* to a const char*, the second converts the argument from A to const A. I.e. both add a const conversion, doesn't that make it ambiguous?

I have found an explaination in the comp.std.c++ archives: see http://groups.google.com/groups?hl=en&threadm=89laut%24ou2%241% 40sun27.hrz.tu-darmstadt.de


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw@jabber.at mailto cmeerw at web.de

August 24, 2003
"Christof Meerwald" <cmeerw@web.de> wrote in message news:biajsc$1v5$1@digitaldaemon.com...
> On 22 Aug 2003, Walter wrote:
> > I have a question about this. The first conversion converts a char* to a const char*, the second converts the argument from A to const A. I.e. both add a const conversion, doesn't that make it ambiguous?
>
> I have found an explaination in the comp.std.c++ archives: see
>
http://groups.google.com/groups?hl=en&threadm=89laut%24ou2%241%40sun27.hrz.t u-darmstadt.de

Thanks. So it should pick the first operator char*()? Argh. I fixed it to
pick the other one!