What is the difference between
(type)value
and
type(value)
in C++?
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.
There is no difference; per the standard (§5.2.3):
Since the question specified the difference between
type(value)and(type)value, there is absolutely no difference.If and only if you’re dealing with a comma-separated list of values can there be a difference. In this case:
As Troubadour pointed out, there are a certain names of types for which the
type(value)version simply won’t compile. For example:will compile, but:
will not. The same type with a different name (e.g., created with a
typedef) can work though: