使用具体输出操作符的声明(带有具体签名)
using declaration for concrete output operator (with concrete signature)
namespace nm
{
class C1 {};
class C2 {};
inline std::ostream& operator << (std::ostream& lhs, std::vector<C1> const&) { return lhs; }
inline std::ostream& operator << (std::ostream& lhs, std::vector<C2> const&) { return lhs; }
}
using nm::operator<<;
是否有办法声明在全局命名空间nm
中只使用operators <<
中的一个,而不是两个?
一种解决方案是将每个operator<<
放在自己的嵌套名称空间中:
namespace nm
{
class C1 {};
class C2 {};
namespace nm1 {
inline std::ostream& operator << (std::ostream& lhs, C1 const&) { return lhs; }
}
namespace nm2 {
inline std::ostream& operator << (std::ostream& lhs, C2 const&) { return lhs; }
}
}
using nm::nm1::operator<<;
现场演示
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- 使用具体输出操作符的声明(带有具体签名)
- 位操作符的优先级对输出的影响
- Cxx-prettyprint(用于标准容器)在命名空间std中定义了它的输出操作符——这违反了标准吗?
- 在模板外部重载模板类的输出流操作符
- 在中缀到后缀的输出中没有操作符和括号
- 输出一个pair列表(由重载操作符创建)
- c++输出操作符重载
- c++重载输出操作符
- 将facet应用于所有流输出,使用自定义字符串操作符
- 重载操作符输出
- 操作符重载等同于c++中的PHP, echo/print类变量作为默认输出
- 操作符重载clang++和g++不同的输出
- 将节点作为输出操作符传递
- 为什么要将对对象的引用作为实参传递给重载输出操作符?
- 解引用操作符和endl没有输出
- 输入/输出操作符的优先级
- 操作符重载- c++ toString输出整数