小编Mic*_*rdt的帖子

为什么行为std :: chrono :: duration :: operator*=不像内置*=?

std :: chrono :: duration :: operator + =中所述,签名是

duration& operator*=(const rep& rhs);
Run Code Online (Sandbox Code Playgroud)

这让我很好奇.我会假设持续时间文字可以像任何其他内置文件一样使用,但事实并非如此.

#include <chrono>
#include <iostream>

int main()
{
    using namespace std::chrono_literals;
    auto m = 10min;
    m *= 1.5f;
    std::cout << " 150% of 10min: " << m.count() << "min" << std::endl;

    int i = 10;
    i *= 1.5f;
    std::cout << " 150% of 10: " << i << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

输出是

150% of 10min: 10min
150% of 10: 15
Run Code Online (Sandbox Code Playgroud)

为什么界面选择那种方式?在我看来,一个界面就像

template<typename T> 
duration& operator*=(const T& …
Run Code Online (Sandbox Code Playgroud)

c++ duration c++11

10
推荐指数
2
解决办法
450
查看次数

标签 统计

c++ ×1

c++11 ×1

duration ×1