Author Topic: [Noob programmer] "Multiple definitions of 'main' "  (Read 12007 times)

otreblA_SNAKE_[ITA]

  • Guest
[Noob programmer] "Multiple definitions of 'main' "
« on: June 23, 2010, 11:25:43 am »
Hi there guys,
I'm studying C++ with Deitel "C++ How To Program" and I've done a small "gradebook" program. However I've a problem: when I try tu build&run my program I've an error:
Quote
C:\Users\Alberto\AppData\Local\Temp\ccSdybij.o:main.cpp|| multiple definition of `main'|
obj\Debug\main.o:C:\Users\Alberto\Documents\Progetti C++ CodeBlocks\ConsoleApplication24\main.cpp|10|first defined here|
||=== Build finished: 2 errors, 0 warnings ===|

Here's my simple program:



gradebook.h
Code
#include <string>
using std::string;

class GradeBook
{
    public:
    GradeBook( string );
    void setCourseName( string );
    string getCourseName();
    void displayMessage();

    private:
    string courseName;
};

gradebook.cpp
Code
#include <iostream>
using std::cout;
using std::endl;



#include "GradeBook.h"


GradeBook::GradeBook( string name )
{
    setCourseName( name );
}


void GradeBook::setCourseName( string name )
{
    if ( name.length() <= 25 )
    courseName = name;

    if ( name.length() > 25 )
    {
        
        courseName = name.substr( 0, 25 );

        cout << "Name \"" << name << "\" exceeds maximum lenght (25).\n" << "Limiting courseName to first 25 characters.\n" << endl;
        
    }

}


string GradeBook::getCourseName()
{
    return courseName;
}


void GradeBook::displayMessage()
{
    
    cout << "Welcome to the GradeBook for\n" << getCourseName() << "!" << endl;
}

Main.cpp
Code
#include <iostream>
using std::cout;
using std::endl;

#include "GradeBook.h"
int main()
{
    //creazione di due oggetti GradeBook
    GradeBook gradeBook1( "CS101 Introduction to C++ Programming" );
    GradeBook gradeBook2( "CS102 Data Structures in C++" );

   
    cout << "gradeBook1's initial name is: " << gradeBook1.getCourseName() << "\ngradeBook2's initial name is: " << gradeBook2.getCourseName() << endl;

   
    gradeBook1.setCourseName( "CS101 C++ Programming" );

   
    cout << "\ngradeBook1's course name is: " << gradeBook1.getCourseName() << "\ngradeBook2's course name is: " << gradeBook2.getCourseName() << endl;
    return 0;
}



In my "Linker Settings" I've included both gradebook.h and gradebook.cpp files but that doesn't help

Thank you,
otreblA
« Last Edit: June 23, 2010, 11:40:07 am by otreblA_SNAKE_[ITA] »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: [Noob programmer] "Multiple definitions of 'main' "
« Reply #1 on: June 23, 2010, 02:26:00 pm »
Please READ:

http://wiki.codeblocks.org/index.php?title=FAQ
Turn on full compiler Logging and post rebuild log; THIS is NOT a website to learn programming!

Please READ: The readme of the sub-forum you posted in http://forums.codeblocks.org/index.php/topic,1519.0.html

Please READ: The readme of sub-forum "General (but related to Code::Blocks) " in http://forums.codeblocks.org/index.php/topic,9996.0.html

Please learn the difference between Code::Blocks Editor/IDE and Compiler or Linker.
Please learn the difference between Compiler and Linker.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org