This may be a simple error but however. I was running my simple programs as normal and then when i went back to the program later to copy some code there was an error message highlighted underneath the first brace of my main() function.

The error states - error: first defined here

I will provide my code as it may be a setup problem with eclipse but i cant figure it out??

Please can someone help me out here?

#include <iostream>
using namespace std;

int main()
{ // error: first defined here
    int a = 1;
    int b = 0;

    // insert statements to output the statements of AND evaluations
    cout << "AND logic:" << endl;
    cout << "(a && a)" << (a && a) << "(true)";
    cout << "(a && b)" << (a && b) << "(false)";
    cout << "(b && b)" << (b && b) << "(true)\n"; // 0 && 0 returns 0 (2 wrongs dont make a right!)

    // insert statements to output the statements of OR evaluations
    cout << "OR logic:" << endl;
    cout << "(a || a)" << (a || a) << "(true)";
    cout << "(a || b)" << (a || b) << "(true)";
    cout << "(b || b)" << (b || b) << "(false)\n";

    cout << endl << "NOT logic:" << endl;
    cout << "a = " << a << " !a = " << !a << "  ";
    cout << "b = " << b << " !b = " << !b << endl;
    return 0;
};

Recommended Answers

All 3 Replies

When I put your code into a new project in VS2012 it runs fine. Could you have 2 main's defined in your project?

Yes this must be the problem. I was doing different exercises and tried to keep them together in the same project. I guess the answer is to split them up in future! Thanks for your help, much appreciated

main is only a subroutine, but there can only be one. Renaming the other would propbably be easier.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.