0

I am trying to overload the ostream cout operator but I am getting errors I do not understand. I managed to make another operator overloading work but this one Im nout sure what I did wrong. It says:

‘std::ostream& Box::operator<<(std::ostream&, Box&)’ must have exactly one argument ostream& operator << (ostream& out, Box& B)

I have tried using std:: but it didn't work. Any suggestions?

class Box{
    
    private:
    int l, b, h;
    public:
    Box()
    {
        l =0; b =0; h=0;
    }
    int getLength()
    {
        return l;
    }
    int getBreadth()
    {
        return b;
    }
    int getHeight()
    {
        return h;
    }

    bool operator<(Box& compare)
    {
        if (l < compare.l || ( b < compare.getBreadth() && l==compare.l ) || (h < compare.h && b==compare.b && l==compare.l) ) return false;
    }   

    // THIS PART 
    ostream& operator << (ostream& out, Box& B)
    {
        out << B.l << " " << B.b << " " << B.h; 
        return out;
    }
                      
    
};
MikeCAT
  • 73,922
  • 11
  • 45
  • 70
Nadin Hasan
  • 29
  • 1
  • 5

0 Answers0