Search code examples
c++compilationcodeblockscincomma-operator

error in compile c++ code right operand of comma operator has no effect


my c++ Code:

std::cin >> newptr->boarding_time.hour,newptr->boarding_time.mins;

error:

C:\Users\hkteco-ir\Desktop\c++\dsdsa\main.cpp|223|warning: right operand of comma operator has no effect [-Wunused-value]|


Solution

  • You're using comma operator, and according to the operator precedence, the code is equivalent as

    std::cin >> newptr->boarding_time.hour;
    newptr->boarding_time.mins;
    

    and the 2nd statement doesn't have any actual effect at all.

    You might want

    std::cin >> newptr->boarding_time.hour >> newptr->boarding_time.mins;