Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

‘int main()’ previously defined here

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading