편집 :C++ 인터페이스 컴파일
나는 해결책을 알아 냈어. 나는 컴파일 지침에 컴비네이션을 추가하지 않고 오류를 발생시키고 있었다.
은 어떻게 프로그램의 Deitel과 Deitel 책 C++을 통해 작업 과정에있어 건물 및 ++ g을 사용하여 C++ 인터페이스를 컴파일에 문제가 충돌했다. 문제는 .h 파일의 클래스를 선언하고 .cpp 파일에서 구현을 정의했지만 필자가 작성한 테스트 파일을 컴파일하려고 할 때 컴파일 및 작동 방법을 파악할 수 없다는 것입니다. 내가받은 해요 g ++ 오류는 다음과 같습니다 누군가가 올바른 방향으로 날 지점 수 있다면
Undefined symbols:
"GradeBook::GradeBook(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
_main in ccohy7fS.o
_main in ccohy7fS.o
"GradeBook::getCourseName()", referenced from:
_main in ccohy7fS.o
_main in ccohy7fS.o
ld: symbol(s) not found
collect2: ld returned 1 exit status<
내가 감사 할 것입니다.
내 헤더 파일 :
//Gradebook 6 Header
//Purpose is to be the class declaration for the class Gradebook 6
//Declare public, privates, and function names.
#include //the standard c++ string class library
using std::string;
//define the class gradebook
class GradeBook
{
public: //all the public functions in the class
GradeBook(string); //constructor expects string input
void setCourseName (string); //method sets course name--needs string input
string getCourseName(); //function returns a string value
void displayMessage(); //to console
private: //all private members of the class
string courseName;
}; //ends the class declaration
내 .cpp 파일은이 :
//Gradebook 6
// The actual implementation of the class delcaration in gradebook6.h
#include
using std::cout;
using std::endl;
#include "gradebook6.h" //include the class definition
//define the class gradebook
GradeBook::GradeBook(string name) //constructor expects string input
{
setCourseName(name); //call the set method and pass the input from the constructor.
}
void GradeBook::setCourseName (string name) //method sets course name--needs string input
{
courseName = name; //sets the private variable courseName to the value passed by name
}
string GradeBook::getCourseName() //function returns a string value
{
return courseName;
}
void GradeBook::displayMessage() //function does not return anything but displays //message to console
{
cout //message here, the pre tag isn't letting it display
} //end function displayMessage
마지막으로, 테스트 파일 나는 인터페이스를 구현하고 테스트하는 데 썼다.
// Gradebook6 Test
// Program's purpose is to test our GradeBook5 header file and file seperated classes
#include
using std::cout;
using std::endl;
#include "gradebook6.h" //including our gradebook header from the local file.
//being program
int main()
{
//create two gradebook objects
GradeBook myGradeBook1 ("CSC 101 Intro to C++ Programming"); //create a default object using the default constructor
GradeBook myGradeBook2 ("CSC 102 Data Structures in C++");
//display intitial course name
cout //another output message here that the code tag does not like
return 0;
}
g ++의 경우 newb이지만 g ++ filename.extension -o filename과 함께 파일을 빌드하고 있습니다. – FloppyDisk
나는 그것을 이해했다. 내 g ++ 컴파일 지침에 -combine을 추가하는 것을 잊었습니다. – FloppyDisk