Thread overview | ||||||
---|---|---|---|---|---|---|
|
August 22, 2003 need explicit cast to convert from A to char const * | ||||
---|---|---|---|---|
| ||||
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 Re: need explicit cast to convert from A to char const * | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christof Meerwald | 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 Re: need explicit cast to convert from A to char const * | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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 Re: need explicit cast to convert from A to char const * | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christof Meerwald | "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! |
Copyright © 1999-2021 by the D Language Foundation