class method problem

This is a discussion on class method problem within the C++ Programming forums, part of the General Programming Boards category; Errors: 22 'Rectangle::Rectangle()' and 'Rectangle::Rectangle()' cannot be 28 'Rectangle::~Rectangle()' and 'Rectangle::~Rectangle()' cannot be 44 parse error at end of input ...

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

    class method problem

    Errors:

    22 'Rectangle::Rectangle()' and 'Rectangle::Rectangle()' cannot be
    28 'Rectangle::~Rectangle()' and 'Rectangle::~Rectangle()' cannot be
    44 parse error at end of input

    If I take out the constructor and destructor deffinition it works... But I want them there, and I want to know why it doesn't like that.

    As for the input error I have no clue what I did wrong =/


    thanks

    Code:
    #include <iostream>
    
    using namespace std;
    
    class Rectangle
    {
       public:
             Rectangle();
             ~Rectangle();
             void SetLength(int length) { this->itsLength = length;}
             int GetLength() const { return this->itsLength; }
             
             void SetWidth(int width) { itsWidth = width;}
             int GetWidth() const { return itsWidth; }
             
       private:
          int itsLength;
          int itsWidth;
    };
    
    Rectangle::Rectangle()
    {
        itsWidth = 5;
        itsLength = 10;
    }
    
    Rectangle::~Rectangle()
    {}
          
    int main(int argc, char *argv[])
    {
       Rectangle theRect;
       cout << "theRect is " << theRect.GetLength() << " feet long.\n";
       cout << "theRect is " << theRect.GetWidth() << " feet wide.\n";
       
       theRect.SetLength(20);
       theRect.SetWidth(10);
       
       cout << "theRect is " << theRect.GetLength() << " feet long.\n";
       cout << "theRect is " << theRect.GetWidth() << " feet wide.\n";
    
      return 0;
    }
    Last edited by Corey; 04-22-2003 at 11:01 AM.

  2. #2
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    Code:
    void SetWidth(int width) { itsWidth = width;)
    should be
    Code:
    void SetWidth(int width) { itsWidth = width;}
    p.s. What the alphabet would look like without q and r.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    24
    Thanks, but that just brought out more errors... BTW, does anybody know of a good way in DevC++ to make the {} and () look more distinct?? If I raise the text size its HUGE, and all the other fonts are terrible...

    errors:

    32 'Rectangle' undeclared(first use this function)
    32 parse error before ';' token
    33 'theRect' undeclared(first use in this function)

  4. #4
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    >Thanks, but that just brought out more errors...
    Then you didn't do it right. It compiles without error on DevC++ for me.
    p.s. What the alphabet would look like without q and r.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    24
    Are you using version 4?? I double checked and I did it right, but it won't compile and I'm using version 5 beta...


    edit: I installed v4 and it compiled fine...
    Last edited by Corey; 04-22-2003 at 11:10 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem in pass a variable to a class
    By nima_pw in forum C# Programming
    Replies: 3
    Last Post: 06-09-2009, 08:30 AM
  2. Looking for criticism on my GameState class
    By Raigne in forum Game Programming
    Replies: 1
    Last Post: 03-21-2008, 10:45 AM
  3. Class Membership Problem
    By josephjah in forum C++ Programming
    Replies: 5
    Last Post: 05-27-2007, 02:48 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21