samedi 27 juin 2015

why my compiler give error when i overload increment operator

i am facing a problem in operator overloading ,when i compile my programe it give me the errors,following is the code :

class box

{

int length;
int width;
int volume;
public:
    box():length(50),width(30)
    {

    }

         box& operator++()
         {
             volume++;
             width++;
             length++;
         }

};

int main()
{
    box b1;

    cout<<++b1;

}

the error it give is "no match for operator <<" my question is why compiler is giving the error although my syntax seems good.

Aucun commentaire:

Enregistrer un commentaire