Click here to Skip to main content
15,886,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three files, one is an interface, main file and the header file. I am using visual studio 2012 express. Below is the code:

C++
// Exercise 3.11 Solution: ex03_11.cpp
// Test program for modified GradeBook class.
#include <iostream>
#include "GradeBook.h"
using namespace std;

// function main begins program execution
int main()
{
   // create a GradeBook object; pass a course name and instructor name
   GradeBook gradeBook( 
      "CS101 Introduction to C++ Programming", "Professor Smith" );

   // display initial value of instructorName of GradeBook object
   cout << "gradeBook instructor name is: " 
      << gradeBook.getInstructorName() << "\n\n"; 

   // modify the instructorName using set function
   gradeBook.setInstructorName( "Assistant Professor Bates" );

   // display new value of instructorName
   cout << "new gradeBook instructor name is: " 
      << gradeBook.getInstructorName() << "\n\n";

   // display welcome message and instructor's name
   gradeBook.displayMessage(); 
} // end main


C++
// Exercise 3.11 Solution: GradeBook.cpp
// Member-function definitions for class GradeBook.
#include <iostream>
#include "GradeBook.h"
using namespace std;

// constructor initializes courseName and instructorName 
// with strings supplied as arguments
GradeBook::GradeBook( string course, string instructor )
{
   setCourseName( course ); // initializes courseName
   setInstructorName( instructor ); // initialiZes instructorName
} // end GradeBook constructor

// function to set the course name
void GradeBook::setCourseName( string name )
{
   courseName = name; // store the course name
} // end function setCourseName

// function to retrieve the course name
string GradeBook::getCourseName()
{
   return courseName;
} // end function getCourseName

// function to set the instructor name
void GradeBook::setInstructorName( string name )
{
   instructorName = name; // store the instructor name
} // end function setInstructorName

// function to retrieve the instructor name
string GradeBook::getInstructorName()
{
   return instructorName;
} // end function getInstructorName

// display a welcome message and the instructor's name
void GradeBook::displayMessage()
{
   // display a welcome message containing the course name
   cout << "Welcome to the grade book for\n" << getCourseName() << "!" 
      << endl;

   // display the instructor's name
   cout << "This course is presented by: " << getInstructorName() << endl;
} // end function displayMessage


C++
/**************************************************************************
 * (C) Copyright 1992-2010 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 **************************************************************************/






// Exercise 3.11 Solution: GradeBook.h
// Definition of GradeBook class that stores an instructor's name.
#include <string> // program uses C++ standard string class
using namespace std;

// GradeBook class definition
class GradeBook
{
public:
   // constructor initializes course name and instructor name
   GradeBook( string, string );
   void setCourseName( string ); // function to set the course name
   string getCourseName(); // function to retrieve the course name
   void setInstructorName( string ); // function to set instructor name
   string getInstructorName(); // function to retrieve instructor name
   void displayMessage(); // display welcome message and instructor name
private:
   string courseName; // course name for this GradeBook
   string instructorName; // instructor name for this GradeBook
}; // end class GradeBook  



/**************************************************************************
 * (C) Copyright 1992-2010 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 **************************************************************************/   

I get the following errors:
Error	1	error LNK2019: unresolved external symbol "public: __thiscall GradeBook::GradeBook(class std::basic_string<char,struct>,class std::allocator<char> >,class std::basic_string<char,struct>,class std::allocator<char> >)" (??0GradeBook@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) referenced in function _wmain	c:\Users\Leetop\documents\visual studio 2012\Projects\ex311\ex311\ex311.obj	ex311



Error	2	error LNK2019: unresolved external symbol "public: void __thiscall GradeBook::setInstructorName(class std::basic_string<char,struct>,class std::allocator<char> >)" (?setInstructorName@GradeBook@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _wmain	c:\Users\Leetop\documents\visual studio 2012\Projects\ex311\ex311\ex311.obj	ex311


Error	3	error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct>,class std::allocator<char> > __thiscall GradeBook::getInstructorName(void)" (?getInstructorName@GradeBook@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _wmain	c:\Users\Leetop\documents\visual studio 2012\Projects\ex311\ex311\ex311.obj	ex311


Error	4	error LNK2019: unresolved external symbol "public: void __thiscall GradeBook::displayMessage(void)" (?displayMessage@GradeBook@@QAEXXZ) referenced in function _wmain	c:\Users\Leetop\documents\visual studio 2012\Projects\ex311\ex311\ex311.obj	ex311



Error	5	error LNK1120: 4 unresolved externals	c:\users\leetop\documents\visual studio 2012\Projects\ex311\Debug\ex311.exe	1	1	ex311
Posted
Updated 13-Jan-14 4:44am
v2
Comments
Jochen Arndt 13-Jan-14 9:58am    
Check your project settings. It seems that GradeBook.cpp is not part of your project.
Ron Beyer 13-Jan-14 10:55am    
Also need to add a "return 0;" at the end of your main function.
CPallini 13-Jan-14 11:55am    
No, that is not required.
Christopher Drake 13-Jan-14 11:01am    
I agree with Jochen. The code builds fine. Excluding GradeBook.cpp from the project reproduces the behavior. Add Existing item to resolve.

'GradeBook.cpp' isn't compiled,so the compiler can't link it
 
Share this answer
 
Comments
H.Brydon 13-Jan-14 22:55pm    
More correctly, it is not part of the project, so it won't get compiled or linked. The errors in question are linker errors...
Wayne.CN 13-Jan-14 23:07pm    
Pretty good
Thank you for the solution:
The problem was that i added the header file GradeBook.h and the source file GradeBook.cpp using the file menu, and hence it wasnt added in the project solution explorer in MS Visual Studio 2012.
The problem was solved when i added these above two file by right clicking the Source files node on the solution explorer -> Add -> Class.

The linking errors are gone:-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900