Issue with line class polymorphism

Hi, I need help in getting my code to output the required text as shown below.
Problem is in my class line constructor, I'm stuck at the moment on how to achieve the output as shown. If anyone could help, I would really appreciate it. Thanks.

Output required:
1 //Ok
Shape() Polygon() Line() //Ok
4 //Ok
Line(Polygon(Shape(Color(0,0,0)) Point(0,0) Point(0,0))) // Not ok

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
28
29
30
31
32
33
34
35
class Point
{
private:
   int x;
   int y;

public:
   Point() : x(0), y(0) {}
   Point(int x, int y) : x(x), y(y) {}

public:
 
};

class Line : public Point 
{
private:
   Point p1;
   Point p2;
	
public:
   Line() :  p1(Point(0, 0)), p2(Point(0, 0)) {}

};

int main() {

	cout << "1" << endl;
	Line l; 
	cout << "Shape() Polygon() Line() "<< endl;
        
        cout << "4" << endl;
	cout << l;
	cout << endl;
Last edited on
playpro10 wrote:
Problem is in my class line constructor


No, your problem is that you haven't overloaded the << operator for objects of class Line, so your code won't know what to do when it sees
cout << l;
Hi lastchance, I'm confused becoz of this-> Polygon(Shape(Color(0,0,0)). So for this do I explicitly type out Polygon(Shape(Color(0,0,0)) in my cout? Thanks btw.
Last edited on
playpro wrote:
Hi lastchance, I'm confused becoz of this-> Polygon(Shape(Color(0,0,0))


Hi @playpro, I'm confused becoz I don't see
this-> Polygon(Shape(Color(0,0,0));
anywhere in your code.
Last edited on
It's ok alr. Thanks.
Topic archived. No new replies allowed.