-
December 17th, 2012, 12:26 AM
#1
[RESOLVED] I"m a NOOB...Why isn't my code working!?
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
- // gb.cpp GradeBook class demonstration after seperating
- // its interface from its implementation
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include "gb1.h"
- using namespace std;
- // function main begins program execution
- int main()
- {
- // create two GradeBook objects
- GradeBook gradeBook1( "CS101 Introduction to C++ Programming" );
- GradeBook gradeBook2( "CS102 Data Structures in C++" );
- //display initial value of courseName for each GradeBook
- cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
- << "\ngradeBook2 created for course: " << gradeBook2.getCourseName()
- << endl;
- } // end main
This is my gb1.cpp
- // gb1.cpp GradeBook member-function definitions. This file contains
- // implementations of the member functions prototyped in gb.h.
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include "gb1.h"
- using namespace std;
- // constructor initializes courseName with string supplied as argument
- GradeBook::GradeBook( string name )
- {
- setCourseName( name ); // call set function to initialize courseName
- } // end GradeBook constructor
- // function to set the course name
- void GradeBook::setCourseName( string name )
- {
- courseName = name; // store the course name in the object
- } // end function setCourseName
- // function to get the course name
- string GradeBook::getCourseName()
- {
- return courseName; // return object's courseName
- } // end function getCourseName
- // display a welcome message to the GradeBook user
- void GradeBook:isplayMessage()
- {
- // call getCourseName to get the courseName
- cout << "Welcome to the grade book for\n" << getCourseName()
- << "!" << endl;
- } // end function displayMessage
This is my gb1.h
- // gb1.h Gradebook class definition. This file presents GradeBook's public
- // interface without revealing the implementation of GradeBook's member
- // functions, which are defined in gb1.cpp.
- #pragma once
- #include "stdafx.h"
- #include <iostream>
- #include <string> // class GradeBook uses C++ standard string class
- using namespace std;
- // GradeBook class definition
- class GradeBook
- {
- public:
- GradeBook( string ); // constructor that initializes courseName
- void setCourseName( string ); // function that sets the course name
- string getCourseName(); // function that gets the course name
- void displayMessage(); // function that displays a welcome message
- private:
- string courseName; // course name for this GradeBook
- }; // 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|