hey guys ! i am new to graphics in c++ .. i have to develop an application called " paint " . i have to implement it using classes ( and inheritance in classes ) . For example i have to draw a line using mouse . All the graphic functions are implemented in the class Graphics.h file. my code is pasted and the exact problem lies below :

#include <iostream>
using namespace std;
class Point 
{
protected : 
    int x1 ;
    int y1 ;
public :

    Point (int _x , int _y)
    {
        x1 = _x ;
        y1 = _y ;
    }
    void SetX (int _x)
    {
        x1 = _x ;
    }
    void SetY (int _y)
    {
        y1 = _y ;
    }
    int GetX () const
    {
        return x1 ;
    }
    int GetY () const
    {
        return y1 ;
    }
    ~Point()
    {}
};

#include <iostream>
using namespace std;
#include "Point.h"
class Line : public Point 
{
public :

    Line (int x2= 0 , int y2=0) : Point (x1,y1)
    {

    }

    ~Line ()
    {
    }
};
#include <iostream>
using namespace std;
#include "circle.h"
#include "graphics.h"
#include "Point.h"
#include "Line.h"
void main ()
{
    int maxx ;
    int maxy ;
    int x2 ;
    int y2 ;
    Line l ;

    initwindow(450,300);
    maxx = getmaxx();
    maxy = getmaxy();


    while (!ismouseclick(WM_LBUTTONDOWN))
    {
        Line(x2,y2);

    }
    getmouseclick(WM_LBUTTONDOWN,x2,y2);

    system("pause");
}

ok the exact problem is in the " while loop " . because i have to draw a line and this function is implemented in the graphics.h file so should i call the constructor of class line in the while loop or the Line function of the graphics.h file ?? Remember i have to implement this assignment using classes .

c++ itself knows nothing about graphics so you have to use operating system api or some 3d party graphics library such as OpenGL and DirectX. See this Microsoft article for GDI functions on MS-Windows. You must be using a fairly recent 32-bit compiler to access those functions. *nix has completly different functions but I'm not familiar with them.

A good graphics library, available on just about every OS in use today, is Qt. It is system independent (works on Windows, Linux, Unix, QNX, and others), and very complete, handling threading very nicely. If you have to do it natively yourself, then you have a lot more work to do. Ask your teacher if they have any suggestions, or limitations, in the graphics API's you are allowed to use.

This article has been dead for over six months. Start a new discussion instead.