首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误C4716:‘运算符<<’:必须返回一个值

错误C4716:‘运算符<<’:必须返回一个值
EN

Stack Overflow用户
提问于 2015-05-22 16:28:17
回答 1查看 4.1K关注 0票数 0

我正在努力为这个操作符获得一个适当的回报(它不是我的代码,只是试图纠正它,我不像我应该在C++中纠正它那样好),任何人都可以帮助我,它是为高级数字电路设计定义的数据类型类。

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

代码语言:javascript
复制
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;

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-22 16:38:16

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

代码语言:javascript
复制
cout << foo << bar << foobar;

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

代码语言:javascript
复制
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
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30401691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档