2013-10-27 6 views
0

헤더 파일 (.h), 클래스 구현 파일 (.cpp) 및 기본 파일 (.cpp)로 간단한 클래스를 만들었습니다.클래스가 제대로 연결되지 않음

나는이 오류 얻을 어디 X-코드 (건물)을 연결하려고 할 때까지 오류가 없을 것 같다 :

int main() 

{ 

bbq barbeque ("coleman", "101a"); 


barbeque.loadCoals(); // print output 

헤더 파일 : 여기

Undefined symbols for architecture x86_64:
"bbq::bbq(std::__1::basic_string, std::__1::allocator >, std::__1::basic_string, std::__1::allocator >)", referenced from: _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)*

그리고 나의 코드 :

class bbq 
{ 
private: 
string brand, model; 



public: 
bbq (string brand, string model); 
void loadCoals();} 

그리고 기능 정의 :

void bbq::loadCoals() 
{ 

cout<<"Loading Coleman Grill 101A with coals!"; 

} 

답변

0

bbq :: bbq (문자열 브랜드, 문자열 모델)를 쓰지 않았습니다. .cpp 파일에서의 구현.

bbq::bbq(string brand, string model) { 
    this->brand = brand; 
    this->model = model; 
} 
+0

감사합니다, 나는 단순히 .cpp 파일 안에 쓰고, 그것을 작동 :

당신은 그것을 구현해야합니다. bbq :: bbq (문자열 브랜드, 문자열 모델) {} 하지만 기능 대괄호 안에 무엇을 배치할까요? 다른 기능은 별도로 정의되어 있습니다. @ 피에르 - 에마뉘엘 - Lallemant – user2924131

+0

내 대답을 수정했습니다;) –

+0

고마워요, 그러나 출력 (<< 브랜드 << 모델), 다음 함수 loadcoals() 내가 뭘 넣어로 문자열을 출력하지 않습니다 : 바베큐 barbecque ("coleman", "101a") 대신에 빈 문자열입니다. @ 피에르 엠마누엘 라일 런트 – user2924131

관련 문제