Unusual static_cast syntax

I managed to track the error to the following expression:

foo(static_cast<T>(a, b)); // Executes specialisation 1 

The closing bracket was in the wrong place. The correct statement should have been:

 foo(static_cast<T>(a), b); // Executes specialisation 2 

I have never seen static_cast used in form (a, b), or seen how it is described anywhere. What does it mean? The previous statement is back.

+5
source share
3 answers

static_cast not a function, it is a keyword, so the comma in a, b not an argument delimiter; it is a comma . It evaluates a but discards the result. The expression evaluates to b .

+15
source

This has nothing to do with static_cast , but "uses" from a comma . His result is his right side, therefore

 foo(static_cast<T>(a, b)); 

equivalently

 foo(static_cast<T>(b)); 

if a has no other effects (which will then be executed and their result will be discarded). With the correct compiler settings, you will be warned of such things: Live

+8
source

, is a comma operator, so a, b is just b

0
source

All Articles