I'm trying to learn how to work with external class files in C++ and have hit a wall. Everything runs just spiffy in xcode, but when trying to run it in the command line I've gotten the following error.
From g++:
Undefined symbols for architecture x86_64: "GradeBook::GradeBook(std::basic_string, std::allocator >)", referenced from: _main in cc9lOO3b.o "GradeBook::getCourseName() const", referenced from: _main in cc9lOO3b.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status
Here's the source code for the class:
// GradeBook.h header file
#include <iostream>
#include "GradeBook.h" // include definition of class GradeBook
// constructor initializes couseName with string supplied as argument
GradeBook::GradeBook ( std::string name )
: courseName ( name ) // member initializer to initialize courseName
{
// empty body
} // end GradeBook constructor
// function that sets the course name
void GradeBook::setCourseName ( std::string name )
{
courseName = name; // store the course name in the objec
} // end function setCourseName
// function that gets the course name
std::string GradeBook::getCourseName() const
{
return courseName; // returns the object's courseName
} // end function getCourseName
// function that displays a welcome message to the GradeBook user
void GradeBook::displayMessage() const
{
// this statement calls getCourseName to get the
// name of the course this Gradebook represents
std::cout << "Welcome to the grade book for\n" << getCourseName() << "!" << std::endl;
} // end function displayMessage
Thanks for taking a look!