How can I use class, constructors and destructors while drawing a circle?

How can I use class, constructors and destructors while drawing a circle? especially please tell me where should i initialize initgraph.

Thanks!

class shape
{
int x;
int y;
int radius;
public:
shape ()
{
x=0;
y=0;
radius=0;
}
shape (int a, int b, int c);

void display ()
{
// should I initialize here?
}
~shape ()
{
cout<<"Destructor called";
}};
shape::shape(int a, int b, int c)
{
x=a;
y=b;
radius=c;
}
int main ()
{
shape s1;
s1.display();
{
shape s2(200,200,100),s3;
s2.display();
}
cout<<"came here";
return 0;
}
Last edited on
// should I initialize here?
Why would you want to initialize in display()? That is presumably an output function, although it doesn't do anything yet.

The proper place to initialize is in the implementation of the constructors, which you are already doing.
s1 and s3 have no arguments, so you will invoke the default constructor for each.
s2 has arguments, so you will invoke shape's 3 argument constructor.

How can I use class, constructors and destructors while drawing a graph? especially please tell me where should i initialize initgraph.

What is initgraph? I see no declaration for it nor a description of it.

All you have defined a a shape class. A shape is not a graph. If you want to represent a graph, then you need a drawing space and the ability to place shapes in the drawing space.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
O sorry guys, I actually wanted to write "circle" instead of "graph" please do read it again.

-Thanks!
Topic archived. No new replies allowed.