Ive almost completly debugged this but im still having errors when i test it. Can someone correct it for me? Im going to give code for my points.h and my test.cpp. I believe all my problems are from the points.h line constructor. I know the point class works fine. No problems with points.
//points.h
#include <winbgim.h>
class point
{
public:
point(int x, int y):X(x),Y(y){}
virtual ~point(){}
virtual void Draw(){}
virtual int setX(int x){X=x;}
virtual int setY(int y){Y=y;}
virtual int getX(){return X;}
virtual int getY(){return Y;}
private:
int X,Y;
};
class line
{
public:
line(point A,point B): p1.setX(A.getX()),p1.setY(A.getY()),p2.setX(B.getX ()),p2.setY(B.getY()){} //Problems with the constructor
~line(){}
virtual void Draw();
private:
point p1;
point p2;
};
void line :: Draw()
{
moveto(p1.getX(),p1.getY());
lineto(p2.getX(),p2.getY());
} //End of points.h
//test.cpp(put this in an empty project)
#include "points.h" // in project options u have to put: -lbgi -lgdi32
int main()
{
initwindow(600,600); //Opens graphics window
point A(10,30); //Declares point A
point B(30,10); //Declares point B
moveto(A.getX(),A.getY()); //Moves pointer to A
lineto(B.getX(),B.getY()); //Draws line from point A to point B
line pp1(point C(40,50),point D(50,60)); //Declares line pp1
pp1.Draw(); //Draws line
while(!kbhit()); //Waits till user hits button on keyboard
closegraph; //Closes graphics window
return 0;
} //End of test.cpp
Im getting the following errors:
1 c:\dev-c_~1\projects\test.cpp
c:\dev-c_~1\projects\points.h: In method `line :: line(point, point)':
19 c:\dev-c_~1\projects\points.h
parse error before `.'
19 c:\dev-c_~1\projects\points.h
parse error at end of saved function text
11 c:\dev-c_~1\projects\test.cpp
request for member `Draw' in `pp1', which is of non-aggregate type `line ()()'
Any help is very appreciated