Which paragraph in the C++ Standard prohibits the conversion of a pointer-to-const into a pointer-to-non-const?

Viewed 116

Which paragraph in the C++ Standard prohibits the conversion from a const char* argument into a char* parameter? I know this is correct. I just would like to know where this is stated in the Standard?

#include <iostream>

std::string message("Hello");

void my_log(char* pchar) {
    std::cout << pchar << '\n';
}


void my_func(const std::string& message)
{
    my_log(const_cast<char*>((&message)->c_str()));     // Ok
    my_log((&message)->c_str());                        // Doesn't compile
}


int main() {
    my_func(message);
}

See live example here.

0 Answers
Related