Why do I get this error?
Luis Pedro Coelho
luis_pedro at netcabo.pt
Sun Nov 10 16:25:45 GMT 2002
Em Domingo, 10 de Novembro de 2002 17:12, Ian Reinhart Geiser escreveu:
> > > /usr/local/src/kdelibs/kabc/plugins/ldap/resourceldap.cpp:98: cannot
> > > convert `QCString()' from type `QCString' to type `char *'
> >
> > Does an explicit cast like
> > (char*)mHost.local8Bit()
> > or
> > (const char*)mHost.local8Bit()
> > help?
>
> This must be a gccism... the (char *) fails with the same error, but the
> (const char *) only gives a warning of discarded qualifiers...
>
> What is the lesser of evils?
gcc is right, though. There is only an QCString::operator const char*() const.
No direct conversion to char*.
The (const char*) cast helps the compiler find it and call it, but then you
try to use it as a char* and it warns you that you are discarding const (if
am looking at the right thing, you are calling ldap_init which takes a char*,
no const qualifier). This is, in fact, illegal c++ and therefore the warning.
You can either leave the warning, though it might cause graver problems in
other gcc versions / other compilers or go the long way around to do it
correctly:
const_cast<char*>(static_cast<const char*>(mHost.local8Bit())).
Cast to const char* using the user-defined operator and cast away the
const-ness.
HTH,
--
Luis Pedro Coelho
"Technology does not always equal progress."
Douglas Coupland
More information about the kde-core-devel
mailing list