错误C4716:"operator<<":必须返回一个值 [英] Error C4716: 'operator<<': must return a value

查看:96
本文介绍了错误C4716:"operator<<":必须返回一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力为该运算符获得适当的回报(这不是我的代码,只是试图对其进行纠正,而我不如我在C ++中所要纠正的那样好),有人可以帮助我吗,它是为数字电路的高级设计定义的数据类型类.

I am struggling to get an appropriate return for this operator (it is not my code, just trying to correct it and I am not as good as I should be in C++ to correct it) can anybody help me with this, it is datatype class defined for high level design of digital circuits.

如何正确返回此 temp ,是否有任何特殊方法?

How to return this temp without an error, is there any special approach to this?

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;
 }

在我添加的位置返回os;

as I add there return os;

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

I got 226 errors which points to systemC library and instances there. Has anybody done declaration of stream operator with regards to systemC classes or have anybody idea how it is done?

推荐答案

您的函数缺少其返回值.<< 运算符应返回对其使用的流的引用,以便您可以像

Your function is missing its return. The << operator should return a reference to the stream that it was using so that you can chain operations together like

cout << foo << bar << foobar;

要修复您的功能,您只需要返回函数中使用的 ostream

To fix your function you just need to return the ostream that you are using in your function

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
}

这篇关于错误C4716:"operator&lt;&lt;":必须返回一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆