小编Nod*_*eJS的帖子

使用运算符重载时,没有运算符“<<”匹配这些操作数

以下尝试运算符重载时发生错误:

#include<iostream>
#include<string>
#include<ostream>
using namespace std;

class Dollar
{
private:
    float currency, mktrate, offrate;
public:
    Dollar(float);
    float getDollar() const;
    float getMarketSoums() const;
    float getofficialSoums() const;
    void getRates();

    // In the following function I was trying to overload "<<" in order to print all the data members:
    friend void operator<<(Dollar &dol, ostream &out)
    {
        out << dol.getDollar() << endl;
        out << dol.getMarketSoums() << endl;
        out << dol.getofficialSoums() << endl;
    }
};

Dollar::Dollar(float d)
{
    currency = d;
}

float Dollar::getDollar() …
Run Code Online (Sandbox Code Playgroud)

c++ overloading ostream

1
推荐指数
1
解决办法
1244
查看次数

标签 统计

c++ ×1

ostream ×1

overloading ×1