2014-09-09 3 views
0

이것이 일반적인 문제인 것으로 알고 있습니다. 그러나 나는 컴파일을 방해 할 것이라고 생각하지 않는 포함 경비원을 제외하고는 헤더 파일에 대한 모든 표준 사례와 지침을 따르는 것처럼 보인다. 설명 된 링커 오류는 CustomerInformation.h가 주 메서드를 포함하는 CPlusPlusTraining.cpp에 포함될 때만 발생합니다. C++ 용 헤더 및 소스 파일 구성

내가 C++ 파일 구성 정보에 사용되는 하나의 소스입니다 : 여기

http://www.umich.edu/~eecs381/handouts/CppHeaderFileGuidelines.pdf가 내 헤더

class CustomerInformation { 

public: CustomerInformation(); 

public: char InformationRequest(); 

}; 

소스

#include "stdafx.h" 
#include <iostream> 
#include <string> 
#include "CustomerInformation.h" 
using namespace std; 

char InformationRequest() { 
     string name; 
     string lastName; 
     int age; 
     cout << "Please input your first and last name then your age: \n"; 
     cin >> name >> lastName >> age; 
     cout << "Customer Information: " << name + " " << lastName + " " << age << "\n"; 

     char correction; 
     cout << "Is all of this information correct? If it is Enter 'Y' if not Enter 'N' \n"; 
     cin >> correction; 

     if (correction == 'N') { 
     cout << "Please Enter your information again: \n"; 
     InformationRequest(); 
     } 

     return correction; 
}` 

그리고 내가

CPlusPlusTraining.cpp에 포함
#include "stdafx.h" 
#include <iostream> 
#include <string> 
#include "CustomerInformation.h" 
using namespace std; 

헤더 파일과 소스 파일의 이름이 같습니다. 소스 파일이 .cpp로 끝나는 동안 헤더 파일은 .h로 끝납니다. 그러나 컴파일 할 때 수많은 링커 오류가 발생합니다. 여기에 어떤 문제가 있습니까? 나는 반복적 인 코드 삽입을 다른 날을 위해 저장할 것이다. 감사.

빌드 시작 : 프로젝트 : CPlusPlusTraining, 구성 : 나는 그것에 홈페이지 내 파일에

CustomerInformation CI = CustomerInformation::CustomerInformation(); 
//information request 
CI.InformationRequest(); //Not type safe for input 

오류 세부 사항 메소드를 호출하는 방법

디버그는 Win32 ------ 1> CPLusPlusTraining.cpp // 메인 _파일 1> CPlusPlusTraining.obj : 오류 LNK2019 : 함수 _wmain에서 참조되는 확인되지 않은 외부 기호 "public : __thiscall CustomerInformation :: CustomerInformation (void)"(?? 0CustomerInformation @@ QAE @ XZ) > CPlusPlusTraining.obj : 오류 LNK2019 : 해결되지 않은 외부 s 함수 _wmain에서 참조 된 ymbol "public : char __thiscall CustomerInformation :: InformationRequest (void)"(? InformationRequest @ CustomerInformation @@ QAEDXZ) 1> C : \ Users \ Gordlo_2 \ documents \ visual 스튜디오 2013 \ Projects \ CPlusPlusTraining \ Debug \ CPlusPlusTraining .exe : 치명적인 오류 LNK1120 : 해결되지 않은 외부가 2 개 = 0 성공, 1 실패, 0 최신, 0 건너 뛰기 ==========

+0

PS, 나는 단순히 아래로 C++의 기초를 얻을 수 비얀 스트로브 스트 룹의 책을 통해려고하고있다. – gordlonious

+0

링커 오류 란 무엇입니까? 당신은 cpp 파일들로 구축하고 있습니까 :'g ++ main.cpp InfoRequest.cpp' –

+0

호출과 에러에 대한 자세한 내용은 제 편집을보십시오. – gordlonious

답변

2

클래스 선언없이 Customer 클래스의 멤버 함수를 선언하여 컴파일러가 사용자가 프로토 타입 화 한 함수임을 알지 못하게합니다. 이 있어야한다 :이 숙제를하지

char CustomerInformation::InformationRequest() { 
//your function stuff 
} 
+0

그게 하나의 오류를 해결! 아직 해결되지 않은 외관을 언급하는 두 가지 오류가 있습니다. – gordlonious

+1

선언되지 않았습니다. 한정된. 선언은 계급 몸에 있고, 정확하고, afaict이다. –

+1

@ gordlonious : 다른 오류는 생성자를 선언했지만 정의하지 않았기 때문에 발생합니다. 클래스를 초기화하기 위해 특별한 작업을 수행 할 필요가 없으면 선언을 제거하거나 수행 한 경우 선언을 제거하십시오. –