This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: typedef & constructor bug


On Mar  8, 2000, Jos van den Oever <Jos.vandenOever@fenk.wag-ur.nl> wrote:

> typedef char * Ptr;

>         Text(const Ptr);

Please note that this is `char *const', not `char const*', i.e., it is
Ptr that is const, not the pointed-to chars.  This explains why GCC
can't construct a Text from the `const char *' in:

>         useText((i>0) ? "ok" : "not ok");

However, because a string literal can be converted to non-const
`char*', if the surrounding context expects a `char*', this also
succeeds:

>         useText((i>0) ? "ok" : Text("ok"));
 
It's equivalent to:

          useText((i>0) ? Text((char*)"ok") : Text((char*)"ok"));

-- 
Alexandre Oliva     http://www.ic.unicamp.br/~oliva/     Enjoy Guaranį
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org}   Write to mailing lists, not to me


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]