错误 C4716: 'operator<<': 必须 return 一个值

Error C4716: 'operator<<': must return a value

我正在努力为这个运算符找到一个合适的return(这不是我的代码,只是想更正它,我在 C++ 中没有达到我应该的水平来更正它)任何人都可以吗帮助我,它是为数字电路的高级设计定义的数据类型 class。

如何return这个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;
 }

正如我在此处添加的 return os;

我收到 226 个错误,指向那里的 systemC 库和实例。有没有人做过关于 systemC classes 的流运算符声明,或者有人知道它是如何完成的?

您的函数缺少 return。 << 运算符应 return 对其使用的流的引用,以便您可以将操作链接在一起,如

cout << foo << bar << foobar;

要修复您的函数,您只需 return 您在函数中使用的 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
}