Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在实现一个输出流运算符<< 重载,我需要检查输出流参数 os 是否为 std::cout,如果不是,则抛出 std::runtime_error - 我该如何检查它?
friend std::ostream& operator<<(std::ostream& os, const Software &soft)
我质疑那种会导致你认为你必须这样做的逻辑,但如果你真的想......
if (&os != &std::cout) { throw std::runtime_error(/* ... */); }