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

Dom*_*lič 0 c++ operator-overloading systemc

我正在努力为这个运算符得到一个适当的返回(这不是我的代码,只是试图纠正它,我不像我应该在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;
 }
Run Code Online (Sandbox Code Playgroud)

当我添加返回os;

我得到226个错误,指向systemC库和那里的实例.有没有人对systemC类做过流操作符的声明,或者有人知道它是如何完成的?

Nat*_*ica 6

你的功能缺少它的回报.该<<运营商应该返回它是使用,这样就可以连锁经营在一起,喜欢流的引用

cout << foo << bar << foobar;
Run Code Online (Sandbox Code Playgroud)

要修复您的功能,您只需要返回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
}
Run Code Online (Sandbox Code Playgroud)