【发布时间】:2014-11-04 22:01:32
【问题描述】:
有没有办法替换默认的
template <typename T, typename charT, typename traits>
std::basic_ostream<charT, traits> &
operator << (std::basic_ostream<charT, traits> &strm, const std::complex<T>& c)
带有我自己版本的标准库?我不能只使用上面的签名重载它,因为编译器抱怨(这是正确的)关于模棱两可的调用。我需要这样的重载,因为我想以不同的格式显示std::complex 数字,例如a + b*i,而不是默认的(a,b)。
我可以简单地做到这一点
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::complex<T>& c)
{
os << real(z) << " + " << imag(z) << "i";
return os;
}
但这不是std 中使用的通用版本,不会被其他库调用,例如 Eigen。
【问题讨论】:
标签: c++ c++11 operator-overloading eigen