Does the unary + operator have any practical use?

前端 未结 9 1773
后悔当初
后悔当初 2020-12-03 16:58

Was the unary + operator only included for symmetry with the unary - operator, or does it find some practical use in C++ code?

Searching h

9条回答
  •  再見小時候
    2020-12-03 17:37

    char ch = 'a';
    std::cout << ch << '\n';
    std::cout << +ch << '\n';
    

    The first insertion writes the character a to cout. The second insertion writes the numeric value of ch to cout. But that's a bit obscure; it relies on the compiler applying integral promotions for the + operator.

提交回复
热议问题