There is no difference; according to the standard (clause 5.2.3):
The simple type specifier (7.1.5), followed by a parenthesized list of expressions, builds the value of the specified type based on the list of expressions. If the list of expressions is a single expression, the type conversion expression is equivalent (in certainty and, if defined in meaning) to the corresponding expression (5.4).
Since the question asks the difference between type(value) and (type)value , there is no difference.
If and only if you are dealing with a comma-separated list of values, there might be a difference. In this case:
If more than one value is specified in the list of expressions, the type must be a class with the corresponding declared constructor (8.5, 12.1), and the expression T (x1, x2, ...) is actually equivalent to the declaration T t (x1, x2, ...); for some invented temporary variable t, the result of which is the value of t as rvalue.
As Troubadour pointed out, there are certain type names for which the version of type(value) simply will not compile. For example:
char *a = (char *)string;
will compile but:
char *a = char *(string);
will not be. The same type with a different name (for example, created using typedef ) may work:
typedef char *char_ptr; char *a = char_ptr(string);
Jerry Coffin Oct 30 '09 at 21:25 2009-10-30 21:25
source share