mercredi 3 juin 2015

Can I directly return an object by returning constructor?

class time
{
    public:
    time(int i, int j, int k)
    {
        hour = i, minute = j, second = k;
    }

    private:
    int hour, minute, second;
}

time return_an_object_1 (void)
{
    return time(1, 30, 59);  // Using parentheses
}

time return_an_object_2 (void)
{
    return time{1, 30, 59};  // Using curly bracket
}

Both can be compiled successfully, but what is the difference?

Aucun commentaire:

Enregistrer un commentaire