mercredi 8 janvier 2020

How to correctly multiply a std::chrono type variable

I have an std::chrono variable with stores a timeout.

const std::chrono::seconds timeout_1 = std::chrono::seconds(4)

Lets say I want to multiply it with a number to deduce another std::chrono::seconds type variable.

const std::chrono::seconds timeout_2 = timeout_1 * 2;

This makes the value of timeout_2 as 4 seconds. Thats perfect!

But if I do it in the following way using a variable then it results in zero?

unsigned int x = 2
const std::chrono::seconds timeout_2 = timeout_1 * x;   // This makes timeout_2 as 0?

Is multiplying std::chrono types by int variables a wrong thing to do?

Aucun commentaire:

Enregistrer un commentaire