重载<<(代码错误)
Overloading << (Error with code)
有没有人能告诉我<<操作符。Visual studio告诉我有很多参数。Node是一个结构
ostream& operator << (ostream& strm, const node* &obj )
{
strm << "ItdID: " << obj.itemId << "nItem Description: " << obj.itemDescription << "nItem Quanity: " << obj.quanity
<< "nWholesale Cost: $" << fixed << showpoint << setprecision(2) << obj.wholesale << "nRetail Cost: $" << fixed << showpoint << setprecision(2) << obj.retail;
return strm;
}
您需要将ostream& operator << (ostream& strm, const node* &obj )
声明为friend
函数到node
类。
那么在你的节点类中你要有
friend ostream& operator << (ostream& strm, const node* &obj );
然后在你的CPP文件中有
ostream& operator << (ostream& strm, const node* &obj )
{
strm << "ItdID: " << obj.itemId << "nItem Description: " << obj.itemDescription << "nItem Quanity: " << obj.quanity
<< "nWholesale Cost: $" << fixed << showpoint << setprecision(2) << obj.wholesale << "nRetail Cost: $" << fixed << showpoint << setprecision(2) << obj.retail;
return strm;
}
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 错误:调用"std::vector<:vector<int>>::p ush_back(std::vector<std::__cxx11::basic_string<
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- &lt;&lt;操作员在C 中超载错误
- opencv 2.4.7在iOS错误背景_segm.hpp #include&lt; list&gt;未找到
- '&lt;'''&lt;'''&quot的模板类错误''令牌”
- 在尝试超载&lt;&lt;时链接错误2005和1169操作员
- 错误:没有匹配'运算符<<"在'std::cout
- 过载<<比如cout错误
- 重载& lt; & lt;为什么我得到以下错误
- 重载ostream&时转换错误无效;operator< & lt;
- 重载<<运算符错误C2804:二进制'运算符<<'参数太多
- 编译器错误,包括'<'代币
- 重载& lt; & lt;错误