Thread: What do these errors mean??

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    24

    What do these errors mean??

    end of file read inside definition

    and

    parse error at end of input


    I am using DevC++, but I get very similair errors with G++... I've looked but don't see anything wrong with the code(but I am only a n00b ) and there isn't even any input lol =/

    thanks

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    not psychic. lets see some code. Dont forget to tag it with code tags.
    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

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    24
    k... This is from Sam's Teach Yourself... It was in 2 files, but I thought there might be a problem so I condensed it to one file, but still getting same error:

    The first error is on line 27, however if that's commented out it has the error on 28, and I presume 29 and 30... The last one is at the end of the file lol =/


    Code:
    #include <iostream.h>
    
    class Point
    {
       public:
          void SetX(int x) { itsX = x; }
          void SetY(int y) { itsY = y; }
          int GetX() const { return itsX;}
          int GetY() const { return itsY;}
       private:
          int itsX;
          int itsY;
    };
    
    
    class Rectangle
    {
       public:
          Rectangle ( int top, int left, int bottom, int right);
          ~Rectangle();
    
          int GetTop() const { return itsTop; }
          int GetLeft() const { return itsLeft; }
          int GetBottom() const { return itsBottom; }
          int GetRight() const { return itsRight; }
    
          Point GetUpperLeft() const { return itsUpperLeft; }
          Point GetLowerLeft() const { return itsLowerLeft; }
          Point GetUpperRight() const { return itsUpperRight; }
          Point GetLowerRight() const { return itsLowerRight; }
    
          void SetUpperLeft(Point Location) {itsUpperLeft = Location;}
          void SetLowerLeft(Point Location) {itsLowerLeft = Location;}
          void SetUpperRight(Point Location) {itsUpperRight = Location;}
          void SetLowerRight(Point Location) {itsLowerRight = Location;}
    
          void SetTop(int top) {itsTop = top;}
          void SetLeft(int left) {itsLeft = left;}
          void SetBottom (int bottom) {itsBottom = bottom;}
          void SetRight (int right) {itsRight = right;}
    
          int GetArea() const;
    
       private:
          Point itsUpperLeft;
          Point itsUpperRight;
          Point itsLowerRight;
          Point itsLowerLeft;
          int itsTop;
          int itsLeft;
          int itsBottom;
          int itsRight;
    };
    
    Rectangle::Rectangle(int top, int left, int bottom, int right)
    {
       itsTop = top;
       itsLeft = left;
       itsBottom = bottom;
       itsRight = right;
    
       itsUpperLeft.SetX(left);
       itsUpperLeft.SetY(top);
    
       itsUpperRight.SetX(right);
       itsUpperRight.SetY(top);
    
       itsLowerLeft.SetX(left);
       itsLowerLeft.SetY(bottom);
    
       itsLowerRight.SetX(right);
       itsLowerRight.SetY(bottom);
    }
    
    int Rectangle::GetArea() const
    {
       int Width = itsRight - itsLeft;
       int Height = itsTop - itsBottom;
       return Width * Height;
    }
    
    int main()
    {
       Rectangle MyRectangle(100, 20, 50, 80);
       int Area = MyRectangle.GetArea();
       cout << "Area: " << Area << "\n";
       cout << "Upper Left X Coordinate: ";
       cout << MyRectangle.GetUpperLeft().GetX();
        cout << "\n";
       return 0;
    }
    Last edited by Corey; 12-18-2002 at 09:32 PM.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    quick scan and the code looks fine.... im guessing that adding a newline after the last brace will clear 2nd error and the first im not sure about.
    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

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    cout << MyRectangle.GetUpperLeft().GetX;

    missing () at end!
    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

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    24
    doh! wtf, I specifically remember typing "GetX()"... I added it though but it still doesn't change the errors, and nneither did adding a newline

  7. #7
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by Corey
    Code:
          Point GetUpperLeft() const { return itsUpperLeft; )
          Point GetLowerLeft() const { return itsLowerLeft; )
          Point GetUpperRight() const { return itsUpperRight; )
          Point GetLowerRight() const { return itsLowerRight; )
    I don't have a compiler right now to check so this might not be the ONLY error, but in the code I quoted, they ended their definitions with end parenthesis instead of brackets.

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    24
    Originally posted by Polymorphic OOP
    I don't have a compiler right now to check so this might not be the ONLY error, but in the code I quoted, they ended their definitions with end parenthesis instead of brackets.
    doh!

    I'm a blind moron... And that error happened in 4 lines due the fact that I'm lazy and prefer copy and paste over typing.

    Thanks a lot...

    Now I'm getting some linker error:

    C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccyWaaaa.o(.tex t+0x158):list0704.cpp: undefined reference to `Rectangle::~Rectangle(void)'

    How do I fix this?
    Last edited by Corey; 12-18-2002 at 09:35 PM.

  9. #9
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    i believe that's the deconstructor (called when the object is destroyed). either take out the line

    ~Rectangle();

    from the Rectangle class, or write a deconstructor function

    such as...

    Code:
    Rectangle::~Rectangle
    {
       //deallocate stuff, etc...
    }
    i think that's right.. it may not be, as i've never used a deconstructor.
    If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrariwise, what it is, it wouldn't be, and what it wouldn't be, it would. You see?

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    24
    Thanks!

    I knew that was a destructor, but didn't think that I had to add that because it has nothing in it...

    and btw, in your code, you forgot the () too

  11. #11
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by MadHatter
    i believe that's the deconstructor (called when the object is destroyed). either take out the line

    ~Rectangle();

    from the Rectangle class, or write a deconstructor function

    such as...

    Code:
    Rectangle::~Rectangle
    {
       //deallocate stuff, etc...
    }
    i think that's right.. it may not be, as i've never used a deconstructor.
    That's right except you forgot the (). It should be

    Rectangle::~Rectangle()
    {
    }

    Also, just to clarify, though it doesn't really matter much, it's "destructor," not "deconstructor"

  12. #12
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    ah, thank you.. i knew it need the (), just wasn't paying enough attention
    If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrariwise, what it is, it wouldn't be, and what it wouldn't be, it would. You see?

  13. #13
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    You can download the code

    You can download the code. (The web address in the book which I don't have with me.)

    A couple of times when I couldn't spot my typos, I tested the downloaded code, and as far as I remember it always worked. Of course it's better to type-in the examples yourself. I think typing in the examples helped me to get a better 'feel' of the language... and to remember the includes and all that stuff.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM