I heard that volatile is factor of overloading like const.
If a function is overloaded by volatile parameter,
when is the volatile-version called?
I can’t imagine a situation when the volatile-version is called.
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.
Volatile can be applied to parameters, but it is not a factor of overloading when applied directly to the parameter. It is however possible to use it to distinguish types of the parameter. For example, this is legal:
This is not:
The reason is that in the first example the reference is not what is volatile, but the integer. In the second example, both types are integers and therefore the same type.
There are also volatile methods. They are akin to declaring
thisto be volatile. Becausethisis a pointer and not the containing type itself, the following is also legal:It is all the same as for overloading by
const.This relevant part of the C++ standard is §13.1 Overloadable declarations. From C++11 draft n3290: