Thread: Help

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Help

    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

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Code:
    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
    You cannot have function calls in this situation. You could solve this by adding a constructor to the point interface which accepts a variable of type point and use this in your constructor of line.

    Example:

    Code:
    class A
    {
        public:
        A (const A& a); 
    };
    
    class B
    {
        public:    
        B (const A& a): InstanceA (a) {}
       
        private:
        A InstanceA;
    };

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Question Can u Give better Example?

    Thank u for the example but i can't think of a way to do that.. Could u give an example by just changing the point.h code to work and post it. If u could i would realy appreciate it.

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Here's the point.h file

    point.h file
    needs to be edited

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Angry Still need help

    Does anyone know how to get it to work

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    line(point A,point B): p1.setX(A.getX()),p1.setY(A.getY()),p2.setX(B.getX ()),p2.setY(B.getY()){}

    line(const point& A,const point& B) : p1(A.getX(),A.getY()),p2(B.getX(),B.getY()) {}

    is that what your after??
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Exclamation Still not working!!!

    IT still doesn't work im going to attach project.PLZ, Someone fix it on there computer and send me it/post it...
    Thank u the few of who have tried to help me so far....

  8. #8
    Registered User
    Join Date
    Dec 2002
    Posts
    43
    This is test file

  9. #9
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Code:
    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()const {return X;}
    virtual int getY()const {return Y;}
    private:
    int X,Y;
    };
    
    class line
    {
    public:
    line(const point& A,const point& B) : p1(A.getX(),A.getY()),p2(B.getX(),B.getY()) {}
    ~line(){}
    virtual void Draw();
    private:
    point p1;
    point p2;
    };
    
    void line :: Draw()
    {
    
    } //End of points.h
    compiles fine on msvc 6 and 7
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  10. #10
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Talking ALmost there

    Alright now that the points.h works i need test.cpp to work with it i'll attach it to this

  11. #11
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Your using nonstandard headers for graphics work. Probably cant help you out more. If you were using winapi it would be much easier for me to help.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: ALmost there

    Originally posted by RPW
    Alright now that the points.h works i need test.cpp to work with it i'll attach it to this
    Have you actually tried fixing this on your own first? Don't post code and expect people to magically fix everything for you. Your code is your own, debug it yourself. If you can't, ask specific questions.

    And read this before posting anymore code.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  13. #13
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Question Winapi

    Whats winapi? Where can i download and is there a good tutorial for it. Sorry im such a pest i just started day after christmas.

    @Hammer
    I've been trying to debug for days and restarted 3 times.

  14. #14
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    whats winapi..... its the windows operating system programming interface. Takes a bit of learning....
    heres some links
    1
    2
    3
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  15. #15
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Red face More Work for me

    Oh well..
    Plz post the winapi.h file so can get it
    Thx alot everyone

Popular pages Recent additions subscribe to a feed