I was reading Deitels' book, and in one of the chapters the reader is supposed to learn how to implement classes by separating the interface in a header file, and the code itself on a source code file.
They use an example where you define a class "GradeBook" that will create a GradeBook for a certain class, and has member functions to set the class name, read the class name and display a "welcome" message.
The problem is I can't even compile the function code... It always returns an error. First it was returning some errors about the class implementation, and now it's returning a linker error...
Anyone knows what's wrong with the code?
gradebook.cpp:
gradebook.h:Code:#include <iostream> #include <string> #include "gradebook.h" using std::cout; using std::string; GradeBook::GradeBook(string name){ setCourseName(name); } void GradeBook::setCourseName(string name){ courseName = name; } string GradeBook::getCourseName(){ return courseName; } void GradeBook::displayMessage(){ cout << "Welcome to GradeBook for: " << getCourseName(); }
I'm not including the main code as the problem is only the class.Code:#include <string> using std::string; class GradeBook { public: GradeBook(string); string getCourseName(); void setCourseName(string); void displayMessage(); private: string courseName; };
Any help appreciated.



LinkBack URL
About LinkBacks



