2 days ago I got the book C++ How to Program /8e by Paul & Harvey Deitel.
In the course of working my way through the book I got stuck on chapter 3
Section 7: Separating Interface from Implementation gradebook case study
Anyway here's what happened:


This is my gradebook1.cpp


  1. // gb.cpp GradeBook class demonstration after seperating
  2. // its interface from its implementation
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <string>
  6. #include "gb1.h"
  7. using namespace std;
  8. // function main begins program execution
  9. int main()
  10. {
  11. // create two GradeBook objects
  12. GradeBook gradeBook1( "CS101 Introduction to C++ Programming" );
  13. GradeBook gradeBook2( "CS102 Data Structures in C++" );
  14. //display initial value of courseName for each GradeBook
  15. cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
  16. << "\ngradeBook2 created for course: " << gradeBook2.getCourseName()
  17. << endl;
  18. } // end main



This is my gb1.cpp


  1. // gb1.cpp GradeBook member-function definitions. This file contains
  2. // implementations of the member functions prototyped in gb.h.
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <string>
  6. #include "gb1.h"
  7. using namespace std;
  8. // constructor initializes courseName with string supplied as argument
  9. GradeBook::GradeBook( string name )
  10. {
  11. setCourseName( name ); // call set function to initialize courseName
  12. } // end GradeBook constructor
  13. // function to set the course name
  14. void GradeBook::setCourseName( string name )
  15. {
  16. courseName = name; // store the course name in the object
  17. } // end function setCourseName
  18. // function to get the course name
  19. string GradeBook::getCourseName()
  20. {
  21. return courseName; // return object's courseName
  22. } // end function getCourseName
  23. // display a welcome message to the GradeBook user
  24. void GradeBook::displayMessage()
  25. {
  26. // call getCourseName to get the courseName
  27. cout << "Welcome to the grade book for\n" << getCourseName()
  28. << "!" << endl;
  29. } // end function displayMessage



This is my gb1.h


  1. // gb1.h Gradebook class definition. This file presents GradeBook's public
  2. // interface without revealing the implementation of GradeBook's member
  3. // functions, which are defined in gb1.cpp.
  4. #pragma once
  5. #include "stdafx.h"
  6. #include <iostream>
  7. #include <string> // class GradeBook uses C++ standard string class
  8. using namespace std;
  9. // GradeBook class definition
  10. class GradeBook
  11. {
  12. public:
  13. GradeBook( string ); // constructor that initializes courseName
  14. void setCourseName( string ); // function that sets the course name
  15. string getCourseName(); // function that gets the course name
  16. void displayMessage(); // function that displays a welcome message
  17. private:
  18. string courseName; // course name for this GradeBook
  19. }; // end class GradeBook



This is the error message


1>gradebook1.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall GradeBook::getCourseName(void)" (?getCourseName@GradeBook@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main
1>gradebook1.obj : error LNK2019: unresolved external symbol "public: __thiscall GradeBook::GradeBook(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0GradeBook@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main


Please help me fix whatever may be wrong, because I can't keep
going through the book while I'm stuck so early on.