C++ で外部クラス ファイルを操作する方法を学ぼうとしていて、壁にぶつかりました。xcode ではすべてがうまく動作しますが、コマンド ラインで実行しようとすると、次のエラーが発生します。
g++ から:
アーキテクチャ x86_64 の未定義シンボル: "GradeBook::GradeBook(std::basic_string, std::allocator >)"、参照元: cc9lOO3b.o の _main "GradeBook::getCourseName() const"、参照元: cc9lOO3b の _main。 o ld: アーキテクチャ x86_64 のシンボルが見つかりません collect2: ld は 1 つの終了ステータスを返しました
クラスのソースコードは次のとおりです。
// 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
ご覧いただきありがとうございます。