Inherited Shape Classes

I'll be upfront this is for an online class assignment and I cannot wait around for short replies from the instructor anymore. I feel that I've got a good amount of the coding completed. The instructions are to write an application that determines the area of a circle and a square, and include the use of classes and constructors. And for the record, I haven't had a C++ class in 8 years so I'm beyond rusty.

I am receiving this error when I debug the program and cannot figure out what "no match for 'operator>>'in" means for this specific situation even after an hour of google time:
squareClass.cpp|17|error: no match for 'operator>>' in '(& std::operator<< <std::char_traits<char> >((* & std::cout), ((const char*)"Enter the Width of the Square ")))->std::basic_ostream<_CharT, _Traits>::operator<< <char, std::char_traits<char> >(((const void*)std::cin.std::basic_istream<char>::<anonymous>.std::basic_ios<_CharT, _Traits>::operator void*<char, std::char_traits<char> >())) >> ((squareClass*)this)->squareClass::Length'|

So far I have started with a base class (shapeClass), and a derived class (squareClass) and wanted to get these working correctly before I start on the circleClass. Any help would be greatly appreciated.

Here's the code I have so far

Shape Class Header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 1  #ifndef SHAPE_H_INCLUDED
 2  #define SHAPE_H_INCLUDED
 3  
 4      //base class
 5  class shapeClass
 6  {
 7      public:
 8          shapeClass();
 9          virtual double getArea();
10          double area;
11  
12  };
13  
14  
15  #endif // SHAPE_H_INCLUDED 


Shape Class .cpp file:
1
2
3
4
5
6
7
8
9
10
11
12
13
 1  #include <iostream>
 2  #include "shapeClass.h"
 3  
 4  using namespace std;
 5  
 6  shapeClass::shapeClass() {
 7      area = 0;
 8  
 9  }
10  double shapeClass::getArea() {
11      return area;
12  
13  }


Square Class Header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 1  #ifndef SQUARE_H_INCLUDED
 2  #define SQUARE_H_INCLUDED
 3  
 4      //derived class
 5  class squareClass : public shapeClass
 6  {
 7  public:
 8      squareClass();
 9      squareClass(double width, double length);
10      double getArea();
11 
12      double Width;
13      double Length;
14      squareClass operator*(squareClass);
15  
16  
17  private:
18  };
19  
20  #endif // SQUARE_H_INCLUDED 


Square Class .cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 1  #include <iostream>
 2  #include "shapeClass.h"
 3  //#include "circleClass.h"
 4  #include "squareClass.h"
 5  using namespace std;
 6  
 7  squareClass::squareClass(){
 8  }
 9 
10  
11  
12  squareClass::squareClass(double width, double length)
13  {
14      cout << "Enter the Length of the Square " << endl;
15      cin >> Width;
16      cout << "Enter the Width of the Square " << endl;
17      cin >> Length;
18  
19      width = Width;
20      length = Length;
21  }
22  
23  double squareClass::getArea()
24  {
25      return Width * Length;
26  
27  }


And finally, the main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 1  #include <iostream>
 2  #include "shapeClass.h"
 3  #include "squareClass.h"
 4  
 5  
 6  
 7  //#include "circleClass.h"
 8  using namespace std;
 9  
10  int main()
11  {
12          //main area object
13      shapeClass area;
14      area.getArea();
15  
16          //inherited area object for area of a square
17      squareClass S_area;
18      S_area.getArea();
19  
20      cout << "The Area of the Square is " << S_area.getArea() << endl;
21  
22  
23      return 0;
24  }
Last edited on
Square Class .cpp:
16 cout << "Enter the Width of the Square " <<

Not sure if this just didn't get cut and pasted into the forum post, but this line has an extra << at the end and no semicolon. Did you mean to put in an endl; like you do on line 14?
Last edited on
Yea that was a mistake when I pasted. I'll fix it.
Lines 14, 18: These lines don't do anything. They do calculate the area, but you don't do anything with the returned result.

Line 17: You call the squareClass default constructor which does not initialize members Width and Length. When you call getArea(), you're going to be calculating based on garbage in Width and Length.

Line 12: You pass width and length in as arguments by value. The statements at lines 19 and 20 don't do anything. You're changing the arguments, but the effect is lost.

Topic archived. No new replies allowed.