Syntax error:
1 2 3 4 5
|
ostream& operator<< (ostream& out, const rectangleType& rect)
{
out << "Length = " << rect.getLength << ", Width = " << rect.getWidth;
return out;
}
|
You forgot parentheses. getLength() and getWidth() are functions.
Logical errors:
1. You wrote a 1, not an l. Perhaps also a good idea to name parameters 'length' and 'width'.
1 2 3 4 5 6
|
void rectangleType::setDimension(double l, double w)
{
if (l >= 0)
length = 1;
// ...
}
|
2. Overloaded << but also wrote nearly identical print() method. Should remove print().
3. Didn't return anything in operator* overload.
Applied the fixes, simplified main(), and put project to
https://repl.it/repls/NervousFALSERectangles
Put your constructors at the top of public, and at the top of the implementation file so that it's the first thing user sees.
Be conservative with the "using namespace std;" -- in main.cpp, go for it, but in header, qualify everything with std:: . It might be okay in rectangleType.cpp , because people don't usually include .cpp files, but I went conservative there and only specified the ones you were using.
I'm a bit curious about the reasoning behind setDimension() logic -- is it really important to have rect.setDimension(-13, 25) turn it into a (0, 25) rectangle instead of just throwing an error?
[Edit: added example to show post-increment operator based on pre-increment operator]