www.digitalmars.com         C & C++   DMDScript  

c++.beta - need explicit cast to convert from A to char const *

reply Christof Meerwald <cmeerw web.de> writes:
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
Aug 22 2003
parent reply "Walter" <walter digitalmars.com> writes:
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
Aug 22 2003
parent reply Christof Meerwald <cmeerw web.de> writes:
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
Aug 24 2003
parent "Walter" <walter digitalmars.com> writes:
"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!
Aug 24 2003