jeudi 20 octobre 2016

Call constructor in if condition as a part of the comma expression?

Here is my code.

#include<iostream>
#include<string>


struct Sales_data {
    Sales_data() = default;

    std::string bookNo;
    unsigned units_sold = 0;
    double revenue = 0.0;
};

int main()
{
    bool a = true;
    if (Sales_data item, a)
        std::cout << a << std::endl;
}

I don't know why the compiler tell me expression must have bool type (or be convertible to bool).

Aucun commentaire:

Enregistrer un commentaire