News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

[Noob programmer] "Multiple definitions of 'main' "

Started by otreblA_SNAKE_[ITA], June 23, 2010, 11:25:43 AM

Previous topic - Next topic

otreblA_SNAKE_[ITA]

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
#include <string>
using std::string;

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

   private:
   string courseName;
};


gradebook.cpp
#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

#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

stahta01

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.next.codeblocks.org/index.php/topic,1519.0.html

Please READ: The readme of sub-forum "General (but related to Code::Blocks) " in http://forums.next.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++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]