Thank you very much for your guide.
The below code gave the result.
I have one question about it. First please have a look at it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <Simple_window.h>
class Smiley : public Circle {
public:
Smiley(Point p, int r): Circle(p,r){}
};
//*******************
int main()
{
Simple_window win(Point(100,100),600,400, "test");
Smiley s(Point(100,100),60);
win.attach(s);
win.wait_for_button();
return 0;
}
|
As you consider, I have created one object here
Smiley s(Point(100,100),60);
and the Smiley's constructor calls the Circle's constructor by parameters. Then the Circle's constructor just stores that
point and
r . The below is code for Circle:
This one from Graph.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
//------------------------------------------------------------------------------
struct Circle : Shape {
Circle(Point p, int rr) // center and radius
:r(rr) { add(Point(p.x-r,p.y-r)); }
void draw_lines() const;
Point center() const;
void set_radius(int rr) { set_point(0,Point(center().x-rr,center().y-rr)); r=rr; }
int radius() const { return r; }
private:
int r;
};
//------------------------------------------------------------------------------
|
And this one from Graph.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 28 29 30 31 32
|
//------------------------------------------------------------------------------
/*
Circle::Circle(Point p, int rr) // center and radius
:r(rr)
{
add(Point(p.x-r,p.y-r)); // store top-left corner
}
*/
//------------------------------------------------------------------------------
Point Circle::center() const
{
return Point(point(0).x+r, point(0).y+r);
}
//------------------------------------------------------------------------------
void Circle::draw_lines() const
{
if (fill_color().visibility()) { // fill
fl_color(fill_color().as_int());
fl_pie(point(0).x,point(0).y,r+r-1,r+r-1,0,360);
fl_color(color().as_int()); // reset color
}
if (color().visibility()) {
fl_color(color().as_int());
fl_arc(point(0).x,point(0).y,r+r,r+r,0,360);
}
}
//------------------------------------------------------------------------------
|
When I ran my code (first one above), it drew a circle. note that please, I haven't called
draw_lines() function yet! It naturally should draw that circle when I would call the
draw_lines() function because the Circle's constructor just stores that
point and
r and (according to the Graph.h and Graph.cpp) it doesn't do any other thing. So why it draws a circle in this situation, please?