I have a function
static bool Validate(const char& letter, string& aWord)
I need to invoke it
Validate(letter, aWord); // where aWord is const
What is the correct way to const_cast in this case?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are absolutely sure that the function does not modify the string, you can do this:
However, a safer thing to do, albeit it an unnecessary copy if the signature could hypothetically be changed to
const, would be to copy the string and pass the copy.If it does change something, your copy would have the results instead, but it would break your logic in the first place.