Why was C++ designed like this?…
(This question is different, but intimately related to
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.
Actually, that’s not completely accurate. The restrictions are:
8.3.6 Default arguments [dcl.fct.default]
So,
thisand local variables can’t be used as defaults.For example, the following is valid:
gwill be called with the valuef(2), which isn’t a compile-time constant. This is an example straight from the standard.The reasons it’s like this is the usual: there either wasn’t a proposal for it, or it was rejected, deemed not necessary or too difficult to implement.