Every time I write a code using Visual Studio for my C++ class, I keep getting reference linking errors and I dont know how to fix it. I have attached the code and the error that I keep getting.

// Fig. 3.7: fig03_07.cpp 47
 // Instantiating multiple objects of the GradeBook class and using
 // the GradeBook constructor to specify the course name
 // when each GradeBook object is created.
 #include <iostream>
 using std::cout;
 using std::endl;

 #include <string> // program uses C++ standard string class
 using std::string;

// GradeBook class definition
 class GradeBook
 // constructor initializes courseName with string supplied as argument
 GradeBook( string name )
 setCourseName( name ); // call set function to initialize courseName
 } // end GradeBook constructor

 // function to set the course name
 void setCourseName( string name )
 courseName = name; // store the course name in the object
 } // end function setCourseName
// function to get the course name 48
 string getCourseName()
 return courseName; // return object's courseName
 } // end function getCourseName

 // display a welcome message to the GradeBook user
 void displayMessage()
 // call getCourseName to get the courseName
 cout << "Welcome to the grade book for\n" << getCourseName()
 << "!" << endl;
 } // end function displayMessage
 string courseName; // course name for this GradeBook
 }; // end class GradeBook

Errors I keep getting:
1>------ Build started: Project: class example2, Configuration: Debug Win32 ------
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\dj000034880\Desktop\Computer Science 2\class example2\Debug\class example2.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\dj000034880\Desktop\Computer Science 2\class example2\class example2\Debug\BuildLog.htm"
1>class example2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Ancient Dragon commented: Excellent post - used code tags and posted error messages :) +24
Re: Complier Not Linking Issues 80 80

Every program must have one main() function. The code you posted does not have that.

Re: Complier Not Linking Issues 80 80

Every program must have one main() function. The code you posted does not have that.

Thank you, I didnt realize I forgot the main function. Once I added the main function it work.

Thank you again for your help.

Be a part of the DaniWeb community

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