Thread: non-aggregate type ??

  1. #1
    qwerty
    Guest

    non-aggregate type ??

    I wrote this program to demonstrate overloading a constructor, but I'm getting an error. Please tell me what's wrong so I can never again make this mistake, thanks
    Error w/ gcc 3.2:
    program.cpp: In function `int main(int, char**)':
    program.cpp:50: request for member `DrawShape' in `theRect1()', which is of
    non-aggregate type `Rectangle ()()'
    Here's the program:
    Code:
    #include <iostream>
    
    using namespace std;
    
    class Rectangle
    {
    public:
      Rectangle ();
      Rectangle (int heigth, int width);
       ~Rectangle ();
      void DrawShape () const;
    private:
      int itsH;
      int itsW;
    };
    
    Rectangle::Rectangle ()
    {
      itsH = 5;
      itsW = 5;
    }
    
    Rectangle::Rectangle (int heigth, int width)
    {
      itsH = heigth;
      itsW = width;
    }
    
    Rectangle::~Rectangle ()
    {
    }
    
    void
    Rectangle::DrawShape () const
    {
      for (int x = 0; x < itsW; x++)
        {
          for (int i = 0; i < itsH; i++)
            cout << "*";
          cout << "\n";
        }
    }
    
    int
    main (int argc, char *argv[])
    {
      Rectangle theRect1 ();
      Rectangle theRect2 (6, 7);
    
      theRect1.DrawShape ();
      theRect2.DrawShape ();
    
      return 0;
    }

  2. #2
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    >Rectangle theRect1 ();
    This is not creating an object of type Rectangle, it's declaring a function called theRect1 returning an object of type Rectangle. Remove the parens and it should work okay.
    p.s. What the alphabet would look like without q and r.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Little Array Difficulty
    By G4B3 in forum C Programming
    Replies: 16
    Last Post: 03-19-2008, 12:59 AM
  3. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  4. Replies: 0
    Last Post: 04-29-2003, 09:23 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM