Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7069887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:30:01+00:00 2026-05-28T05:30:01+00:00

I am getting the following error: Multiple definition of `main’ I have created a

  • 0

I am getting the following error: Multiple definition of `main’

I have created a new project, there are two c++ files in it:

File 1

#include <iostream>

 using namespace std;

int main()
{
    cout<<"Hello World";
    //fflush(stdin);
    //getchar();
    return 0;
}

File 2

#include <iostream>

using namespace std;

int main()
{
    cout<<"Demo Program";
    return 0;
}

When I press Build project and Run, I get error. How do I run these files?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:30:01+00:00Added an answer on May 28, 2026 at 5:30 am

    You cannot have two main functions in the same project. Put them in separate projects or rename one of the functions and call it from the other main function.

    You can never have more than one main() function in your project since it is the entrypoint, no matter what the parameter list is like.

    You can however have multiple declarations of other functions as long as the parameter list is different (function overloading).

    File 1

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        cout<<"Hello World";
        otherFunction();
        return 0;
    }
    

    File 2

    #include <iostream>
    
    using namespace std;
    
    void otherFunction()
    {
        cout<<"Demo Program";
    }
    

    Dont forget the appropiate #includes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this runtime error from a new project. I actually don't have
I have to use an external library, but am getting a multiple definition error
having trouble getting my directx going I get the following error 1>Linking... 1>main.obj :
I'm getting the following error when I try multiple end points.. System.ServiceModel.AddressAlreadyInUseException: The TransportManager
Getting following error by clicking multiple times on a simple link with some basic
I'm getting the following error in output window of Xcode: bool _WebTryThreadLock(bool), 0x9644290: Multiple
After a while and requesting multiple pages I am getting the following error. How
Am getting following error message on calling WCF service: The formatter threw an exception
I am Getting following error on exporting the video using [exportSession exportAsynchronouslyWithCompletionHandler:^ Error: -[TiBlob
I am getting following error while installing the application on my device. before running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.