I am taking programming 2 online, and I seemed to do pretty well in programming 1 but I am really struggling with classes and operator overloading. I am using Dev-C++ and it keeps giving me an error message: 34 C:\CPP\4 - 1\rectangleType.h `rectangleType rectangleType::operator++(rectangleType&, int)' must take either zero or one argument
and
35 C:\CPP\4 - 1\rectangleType.h `rectangleType rectangleType::operator--(rectangleType&, int)' must take either zero or one argument
I am also having issues with allowing the member functions to access the private variables. The assignment is to "Write the definitions of the functions to overload the increment, decrement, arithmetic, and relational operators as members of the class rectangleType, also write a program that tests operations on that class."
//This file is originally from the book examples, but I have modified it for the assignment
//This program shows how to use the class rectangleType.
#include <iostream>
#include "rectangleType.h"
usingnamespace std;
int main()
{
rectangleType rectangle1(23, 45); //Line 1
rectangleType rectangle2(12, 10); //Line 2
rectangleType rectangle3; //Line 3
rectangleType rectangle4; //Line 4
cout << "Line 5: rectangle1: "; //Line 5
rectangle1.print(); //Line 6
cout << endl; //Line 7
cout << "Line 8: rectangle2: "; //Line 8
rectangle2.print(); //Line 9
cout << endl; //Line 10
rectangle3 = rectangle1 + rectangle2; //Line 11
cout << "Line 12: rectangle3: "; //Line 12
rectangle3.print(); //Line 13
cout << endl; //Line 14
rectangle4 = rectangle1 * rectangle2; //Line 15
cout << "Line 16: rectangle4: "; //Line 16
rectangle4.print(); //Line 17
cout << endl; //Line 18
if (rectangle1 == rectangle2) //Line 19
cout << "Line 20: rectangle1 and "
<< "rectangle2 are equal." << endl; //Line 20
else //Line 21
cout << "Line 22: rectangle1 and "
<< "rectangle2 are not equal."
<< endl; //Line 22
if (rectangle1 != rectangle3) //Line 23
cout << "Line 24: rectangle1 and "
<< "rectangle3 are not equal."
<< endl; //Line 24
else //Line 25
cout << "Line 25: rectangle1 and "
<< "rectangle3 are equal." << endl; //Line 26
//start my code*****************************
cout << endl << "--Start of my code--" << endl;
rectangle3 = rectangle1 - rectangle2;
cout << "Rectangle1 - Rectangle2: ";
rectangle3.print();
cout << endl;
rectangle3 = rectangle1 / rectangle2;
cout << "Rectangle1 / Rectangle2: ";
rectangle3.print();
cout << endl;
if (rectangle1 < rectangle2)
cout << "Line 24: rectangle1 is less than rectangle2." << endl;
else
cout << "Line 24: rectangle1 is NOT less than rectangle2." << endl;
if (rectangle1 > rectangle2)
cout << "Line 24: rectangle1 is more than rectangle2." << endl;
else
cout << "Line 24: rectangle1 is NOT more than rectangle2." << endl;
cout << "Rectangle4 is now equal to Rectangle2" << endl;
rectangle4 = rectangle2;
if (rectangle2 <= rectangle4)
cout << "Line 24: rectangle2 is less than or equal to rectangle4." << endl;
else
cout << "Line 24: rectangle2 is NOT less than or equal to rectangle4." << endl;
if (rectangle2 >= rectangle4)
cout << "Line 24: rectangle2 is greater than or equal to rectangle4." << endl;
else
cout << "Line 24: rectangle2 is NOT greater than or equal to rectangle4." << endl;
cout << "Rectangle3: ";
rectangle3.print();
cout << endl;
/*
cout << "Rectangle3 after increment (++rectangle3): ";
++rectangle3;
rectangle3.print();
cout << endl;
*/
cout << "Rectangle3 after increment (rectangle3++): ";
rectangle3++;
rectangle3.print();
cout << endl;
cout << "Rectangle2 set to 8,15" << endl;
rectangle2.setdimension(8,15);
cout << "Rectangle2 after decrement (--rectangle2): ";
--rectangle2;
rectangle2.print();
cout << endl;
/*
cout << "Rectangle2 after decrement (rectangle2--); ";
rectangle2--;
rectangle2.print();
cout << endl;
*/
cout << "--End of my code--" << endl;
//end my code*************************************
return 0;
}
Forgive the random code omissions, I was trying to troubleshoot. I have been working at this for several hours and if I make the variables public, I only have 2 error messages (the ones listed at the beginning). Can anybody tell me what is going on here, and how to fix it? I don't understand the error message, but from the research I have done I am thinking it has something to do with my function prototype and definition. I just really need a hint on fixing this. Once I can get it to compile without those error messages, I think I can get the rest on my own. Thank you for reading!
Operator ++ takes zero or one arguments depending on which one you want. One of them takes a dummy int argument (I believe that is postfix but I could be wrong). Thus, your operator++ that is taking a rectangle& as well is incorrect I think.
EDIT: I just noticed that's exactly what the error message says. :P