Muneeb Zulfiqar
Muneeb Zulfiqar

Reputation: 1023

const char* difference in custom String class

I have a generic type of String which has the value of my certificate cert.pem I am passing it to a function with casting to const char* but it does not work. My Code is below that is not working

String sCertificate = "cert.pem";
if ( SSL_CTX_use_certificate_file(ctx,(const char*)&sCertificate, SSL_FILETYPE_PEM) <= 0 )
        {
                mPtrLogger->logMsg(CF, "", "Unable to Load Certificate file", INFO);
                abort();
        }

and this code works

if ( SSL_CTX_use_certificate_file(ctx,"cert.pem", SSL_FILETYPE_PEM) <= 0 )
        {
                mPtrLogger->logMsg(CF, "", "Unable to Load Certificate file", INFO);
                abort();
        }

I cant seem to understand what the problem is.

Upvotes: 0

Views: 128

Answers (1)

Thomas Matthews
Thomas Matthews

Reputation: 57688

Unless the String type has an overloaded conversion operator, you can't convert by casting. (Think of this like casting one of your complex classes to char *.)

Review the methods of String and choose one that returns a char *. The std::string has the methods c_str and data.

Upvotes: 2

Related Questions