0

我正在努力为这个运算符获得适当的回报(这不是我的代码,只是试图更正它,而且我不如我应该在 C++ 中更正它)任何人都可以帮我解决这个问题,它是数据类型类定义为数字电路的高级设计。

如何在temp没有错误的情况下返回这个,有什么特殊的方法吗?

inline friend std::ostream& operator << ( std::ostream& os, const sc_float &v)
{
   if (c_DEBUG) std::cout << "debug: operator << called " << endl; //debug
   // fixme - this is only copy of sc_float2double function
   double temp;
   temp = (double)v.man / exp2(m_width);
   temp += 1.0;
   temp *= exp2((double)v.exp - exp2((double)e_width - 1.0) + 1.0);
   temp *= (v.sign == true ? -1.0 : 1.0);
   //os << "(" << v.sign << " , " << v.exp << " , " << v.man << ")"; // debug
   os << temp;
 }

当我添加返回操作系统时;

我收到了 226 个错误,这些错误指向那里的 systemC 库和实例。是否有人针对 systemC 类完成了流运算符的声明,或者有人知道它是如何完成的?

4

1 回答 1

6

您的函数缺少返回值。操作员应该返回对它正在使用的流的<<引用,以便您可以将操作链接在一起,例如

cout << foo << bar << foobar;

要修复你的函数,你只需要返回ostream你在函数中使用的

inline friend std::ostream& operator << ( std::ostream& os, const sc_float &v)
{
    //...
    os << temp;
    return os;// <-- this returns the stream that we are unsing so it can be used by other functions
}
于 2015-05-22T16:38:16.390 回答