Home > Software engineering >  ‘int main()’ previously defined here
‘int main()’ previously defined here

Time:06-11

I did this code and faced an error that I can't understand what it is. I run this program in VS code and compilation was successful but getting an compilation error in GFG portal.

#include <iostream>

using namespace std;
/*
* Create classes Rectangle and RectangleArea
*/
int l,b, result;

class Rectangle
{
   public:
      void display()
      {
        cout<<l <<" "<< b<<endl;
      }
};

class RectangleArea : public Rectangle
{
  public:
    void read_input()
    {
        cin >> l >> b;
    }
    void display()
    {
        result = l* b;
        cout<<result;
    }
};

int main()
{
 /*
 * Declare a RectangleArea object
 */
 RectangleArea r_area;

  /*
  * Read the width and height
  */
  r_area.read_input();

/*
 * Print the width and height
 */
  r_area.Rectangle::display();

  /*
  * Print the area
  */
  r_area.display();

   return 0;
  }

And this is the error I got. Help me.

This is the GFG problem that I'm doing.

CodePudding user response:

Don't paste the main function, the portal adds it again to the source so it appears twice.

  • Related