간단한 클래스를 작성하고 오류가 발생합니다. 헤더 파일은 다음과 같습니다 :참조 문자열을 잘못 전달했습니다. C++
그리고 방법 파일은 다음과 같습니다 :
// temp.cpp
#include "temp.h"
#include <string>
using namespace std;
GameEntry::GameEntry(const string &n, int s):name(n),score(s) {}
string GameEntry::getName() { return name; }
int GameEntry::getScore() { return score; }
주요 파일은 다음과 같습니다
#include <iostream>
#include <string>
#include "temp.h"
using namespace std;
int main() {
string str1 = "Kenny";
int k = 10;
GameEntry G1(str1,k);
return 0;
}
는이 같은 오류가 발생했습니다 :
Undefined symbols for architecture x86_64:
"GameEntry::GameEntry(std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> > const&, int)", referenced from:
_main in main1-272965.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can anyon 뭐가 잘못 됐는지 말해줘? 많은 감사합니다.
GameEntry::GameEntry(const string &n, int s):name(n),score(s) {}
편집 : 사실 당신이 정의에 넣을 수 있지만 정의와 선언 모두에 넣을 수 없습니다
어떻게 컴파일러와 링커를 호출 했습니까? 'temp.o '와의 링크를 잊어 버린 것 같습니다. – 5gon12eder
어떻게 컴파일하고 있습니까? 명령 줄이란 무엇입니까? – joelmeans
난 그냥 "C++ main.cpp"시도하고 일반적으로 나를 위해 작동합니다. – Kenny